[libvirt PATCH 8/8] tools: virt-admin: do not leak daemon-log settings

Ján Tomko jtomko at redhat.com
Sun Aug 2 22:11:31 UTC 2020


The commands daemon-log-filters and daemon-log-outputs
are used both for getting and setting the variables.
But the getter receives an allocated string, which
we do not free.

Use separate variables for the getter and the setter
to get rid of the memory leak and to stop casting
away the const.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tools/virt-admin.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 4856758b4e..07d5f49825 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1040,17 +1040,17 @@ static const vshCmdOptDef opts_daemon_log_filters[] = {
 static bool
 cmdDaemonLogFilters(vshControl *ctl, const vshCmd *cmd)
 {
-    char *filters = NULL;
     vshAdmControlPtr priv = ctl->privData;
 
     if (vshCommandOptBool(cmd, "filters")) {
-        if ((vshCommandOptStringReq(ctl, cmd, "filters",
-                                    (const char **) &filters) < 0 ||
+        const char *filters = NULL;
+        if ((vshCommandOptStringReq(ctl, cmd, "filters", &filters) < 0 ||
              virAdmConnectSetLoggingFilters(priv->conn, filters, 0) < 0)) {
             vshError(ctl, _("Unable to change daemon logging settings"));
             return false;
         }
     } else {
+        g_autofree char *filters = NULL;
         if (virAdmConnectGetLoggingFilters(priv->conn,
                                            &filters, 0) < 0) {
             vshError(ctl, _("Unable to get daemon logging filters information"));
@@ -1093,17 +1093,17 @@ static const vshCmdOptDef opts_daemon_log_outputs[] = {
 static bool
 cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *cmd)
 {
-    char *outputs = NULL;
     vshAdmControlPtr priv = ctl->privData;
 
     if (vshCommandOptBool(cmd, "outputs")) {
-        if ((vshCommandOptStringReq(ctl, cmd, "outputs",
-                                    (const char **) &outputs) < 0 ||
+        const char *outputs = NULL;
+        if ((vshCommandOptStringReq(ctl, cmd, "outputs", &outputs) < 0 ||
              virAdmConnectSetLoggingOutputs(priv->conn, outputs, 0) < 0)) {
             vshError(ctl, _("Unable to change daemon logging settings"));
             return false;
         }
     } else {
+        g_autofree char *outputs = NULL;
         if (virAdmConnectGetLoggingOutputs(priv->conn, &outputs, 0) < 0) {
             vshError(ctl, _("Unable to get daemon logging outputs information"));
             return false;
-- 
2.26.2




More information about the libvir-list mailing list