]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuhotplugtest: Resolve some memleaks
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Jul 2013 10:38:02 +0000 (12:38 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Jul 2013 12:16:53 +0000 (14:16 +0200)
If testQemuHotplugAttach succeeds, the vm->def steals the dev pointer.
However, not the envelope, which needs to be freed. In addition,
driver.config is allocated, but never freed.

tests/qemuhotplugtest.c

index d4971c20c33bb954f6c53080332038065f63a158..5e8c5f02758e2aeba0c327b6ee1bc721a09130af 100644 (file)
@@ -89,6 +89,10 @@ testQemuHotplugAttach(virDomainObjPtr vm,
     switch (dev->type) {
     case VIR_DOMAIN_DEVICE_CHR:
         ret = qemuDomainAttachChrDevice(&driver, vm, dev->data.chr);
+        if (!ret) {
+            /* vm->def stolen dev->data.chr so we ought to avoid freeing it */
+            dev->data.chr = NULL;
+        }
         break;
     default:
         if (virTestGetVerbose())
@@ -214,11 +218,6 @@ testQemuHotplug(const void *data)
     switch (test->action) {
     case ATTACH:
         ret = testQemuHotplugAttach(vm, dev);
-        if (!ret) {
-            /* avoid @dev double free on success,
-             * as @dev is part of vm->def now */
-            dev = NULL;
-        }
         break;
 
     case DETACH:
@@ -323,6 +322,7 @@ mymain(void)
 
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
+    virObjectUnref(driver.config);
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }