]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
logging: Resolve mem leak in virLogDaemonPreExecRestart
authorJohn Ferlan <jferlan@redhat.com>
Wed, 2 Dec 2020 12:43:19 +0000 (07:43 -0500)
committerJán Tomko <jtomko@redhat.com>
Wed, 2 Dec 2020 15:15:43 +0000 (16:15 +0100)
Initialize and free @magic since virJSONValueObjectAppendString
does not free it for us eventually.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/logging/log_daemon.c

index be93c63eb5c917bfa30efe08c8f3d4975976b15b..6b8f3b6fe520bd450adb1c159e4b203d42e48865 100644 (file)
@@ -508,7 +508,7 @@ virLogDaemonPreExecRestart(const char *state_file,
     virJSONValuePtr child;
     char *state = NULL;
     virJSONValuePtr object = virJSONValueNewObject();
-    char *magic;
+    char *magic = NULL;
 
     VIR_DEBUG("Running pre-restart exec");
 
@@ -523,10 +523,8 @@ virLogDaemonPreExecRestart(const char *state_file,
     if (!(magic = virLogDaemonGetExecRestartMagic()))
         goto cleanup;
 
-    if (virJSONValueObjectAppendString(object, "magic", magic) < 0) {
-        VIR_FREE(magic);
+    if (virJSONValueObjectAppendString(object, "magic", magic) < 0)
         goto cleanup;
-    }
 
     if (!(child = virLogHandlerPreExecRestart(logDaemon->handler)))
         goto cleanup;
@@ -559,6 +557,7 @@ virLogDaemonPreExecRestart(const char *state_file,
     abort(); /* This should be impossible to reach */
 
  cleanup:
+    VIR_FREE(magic);
     VIR_FREE(state);
     virJSONValueFree(object);
     return -1;