]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemumonitortestutils: Resolve resource leaks found by Valgrind
authorJohn Ferlan <jferlan@redhat.com>
Mon, 4 Feb 2013 18:31:46 +0000 (13:31 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 7 Feb 2013 19:08:14 +0000 (14:08 -0500)
When Valgrind runs the 'qemumonitorjsontest' it would claim that the
thread created is leaked. That's because the virThreadJoin won't get
called due to the 'running' flag being cleared.  In order to avoid that,
call virThreadJoin unconditionally at cleanup time.  Also noted that the
qemuMonitorTestWorker() didn't get the test mutex lock on the failure path.

The incoming and outgoing buffers allocated by qemuMonitorTestIO() and
qemuMonitorTestAddReponse() were never VIR_FREE()'d in qemuMonitorTestFree().

tests/qemumonitortestutils.c

index 7b90c385f9466d3e697b806de3bff804c8301cab..1ed42ce91bba292b24cb052977cecf7f9dbaf31c 100644 (file)
@@ -308,6 +308,7 @@ static void qemuMonitorTestWorker(void *opaque)
         virMutexUnlock(&test->lock);
 
         if (virEventRunDefaultImpl() < 0) {
+            virMutexLock(&test->lock);
             test->quit = true;
             break;
         }
@@ -370,12 +371,14 @@ void qemuMonitorTestFree(qemuMonitorTestPtr test)
 
     virObjectUnref(test->vm);
 
-    if (test->running)
-        virThreadJoin(&test->thread);
+    virThreadJoin(&test->thread);
 
     if (timer != -1)
         virEventRemoveTimeout(timer);
 
+    VIR_FREE(test->incoming);
+    VIR_FREE(test->outgoing);
+
     for (i = 0 ; i < test->nitems ; i++)
         qemuMonitorTestItemFree(test->items[i]);
     VIR_FREE(test->items);