]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu_agent: Resolve Coverity RESOURCE_LEAK
authorJohn Ferlan <jferlan@redhat.com>
Wed, 27 Aug 2014 18:42:41 +0000 (14:42 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 28 Aug 2014 12:12:16 +0000 (08:12 -0400)
Coverity found that on error paths, the 'arg' value wasn't be cleaned
up. Followed the example in qemuAgentSetVCPUs() where upon successful call
to qemuAgentCommand() the 'cpus' is set to NULL; otherwise, when cleanup
occurs the free the memory for 'arg'

src/qemu/qemu_agent.c

index a10954ae58ac3a87d7f1a62ac242f685cb4ce768..fe38f6df9582063b4b80277fd0114c586b5c1570 100644 (file)
@@ -1328,7 +1328,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char **mountpoints,
                       unsigned int nmountpoints)
 {
     int ret = -1;
-    virJSONValuePtr cmd, arg;
+    virJSONValuePtr cmd, arg = NULL;
     virJSONValuePtr reply = NULL;
 
     if (mountpoints && nmountpoints) {
@@ -1343,7 +1343,8 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char **mountpoints,
     }
 
     if (!cmd)
-        return -1;
+        goto cleanup;
+    arg = NULL;
 
     if (qemuAgentCommand(mon, cmd, &reply, true,
                          VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
@@ -1355,6 +1356,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char **mountpoints,
     }
 
  cleanup:
+    virJSONValueFree(arg);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;