]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: virt-admin: do not leak daemon-log settings
authorJán Tomko <jtomko@redhat.com>
Sun, 2 Aug 2020 21:35:16 +0000 (23:35 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 3 Aug 2020 13:19:29 +0000 (15:19 +0200)
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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
tools/virt-admin.c

index 8240d148b0145d85604ebe45af5b43bf2a8285bb..563415ef1f3b6258163fc3b47d0ecfaa3e4ecfc1 100644 (file)
@@ -1037,17 +1037,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"));
@@ -1090,17 +1090,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;