]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
locking: Resolve mem leak in virLockDaemonPreExecRestart
authorJohn Ferlan <jferlan@redhat.com>
Wed, 2 Dec 2020 12:43:20 +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/locking/lock_daemon.c

index 57c7fb088f486f8534b06224f39bc5134bc334e1..851e9fc6f0ceb8aea03311e821043b04e6d9c28e 100644 (file)
@@ -700,7 +700,7 @@ virLockDaemonPreExecRestart(const char *state_file,
     virJSONValuePtr child;
     char *state = NULL;
     virJSONValuePtr object = virJSONValueNewObject();
-    char *magic;
+    char *magic = NULL;
     virHashKeyValuePairPtr pairs = NULL, tmp;
     virJSONValuePtr lockspaces;
 
@@ -748,10 +748,8 @@ virLockDaemonPreExecRestart(const char *state_file,
     if (!(magic = virLockDaemonGetExecRestartMagic()))
         goto cleanup;
 
-    if (virJSONValueObjectAppendString(object, "magic", magic) < 0) {
-        VIR_FREE(magic);
+    if (virJSONValueObjectAppendString(object, "magic", magic) < 0)
         goto cleanup;
-    }
 
     if (!(state = virJSONValueToString(object, true)))
         goto cleanup;
@@ -775,6 +773,7 @@ virLockDaemonPreExecRestart(const char *state_file,
     abort(); /* This should be impossible to reach */
 
  cleanup:
+    VIR_FREE(magic);
     VIR_FREE(pairs);
     VIR_FREE(state);
     virJSONValueFree(object);