]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix Memory Leak in testMessageArrayRef()
authorNehal J Wani <nehaljw.kkd1@gmail.com>
Sun, 30 Mar 2014 21:35:56 +0000 (03:05 +0530)
committerEric Blake <eblake@redhat.com>
Mon, 31 Mar 2014 20:56:17 +0000 (14:56 -0600)
While running virdbustest, it was found that valgrind pointed out
the following memory leaks:

==9996== 17 (8 direct, 9 indirect) bytes in 1 blocks are definitely lost in loss record 9 of 36
==9996==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==9996==    by 0x4A06B62: realloc (vg_replace_malloc.c:662)
==9996==    by 0x4C6B587: virReallocN (viralloc.c:245)
==9996==    by 0x4C6B6AE: virExpandN (viralloc.c:294)
==9996==    by 0x4C82B54: virDBusMessageDecodeArgs (virdbus.c:907)
==9996==    by 0x4C83463: virDBusMessageDecode (virdbus.c:1141)
==9996==    by 0x402C45: testMessageArrayRef (virdbustest.c:273)
==9996==    by 0x404E71: virtTestRun (testutils.c:201)
==9996==    by 0x401C2D: mymain (virdbustest.c:479)
==9996==    by 0x4055ED: virtTestMain (testutils.c:789)
==9996==    by 0x3E6CE1ED1C: (below main) (libc-start.c:226)
==9996==
==9996== 28 (16 direct, 12 indirect) bytes in 1 blocks are definitely lost in loss record 12 of 36
==9996==    at 0x4A06BE0: realloc (vg_replace_malloc.c:662)
==9996==    by 0x4C6B587: virReallocN (viralloc.c:245)
==9996==    by 0x4C6B6AE: virExpandN (viralloc.c:294)
==9996==    by 0x4C82B54: virDBusMessageDecodeArgs (virdbus.c:907)
==9996==    by 0x4C83463: virDBusMessageDecode (virdbus.c:1141)
==9996==    by 0x402C45: testMessageArrayRef (virdbustest.c:273)
==9996==    by 0x404E71: virtTestRun (testutils.c:201)
==9996==    by 0x401C2D: mymain (virdbustest.c:479)
==9996==    by 0x4055ED: virtTestMain (testutils.c:789)
==9996==    by 0x3E6CE1ED1C: (below main) (libc-start.c:226)
==9996==

Signed-off-by: Eric Blake <eblake@redhat.com>
tests/virdbustest.c

index 1870f35c631e04ebf9e89fd4635834211d66c9d5..a798fbefbb9b1f275f0e54eccd1c4d509a65849f 100644 (file)
@@ -250,6 +250,7 @@ static int testMessageArrayRef(const void *args ATTRIBUTE_UNUSED)
     size_t out_nstrv2 = 0;
     const char *in_str2 = "World";
     char *out_str1 = NULL, *out_str2 = NULL;
+    size_t i;
 
     if (!(msg = dbus_message_new_method_call("org.libvirt.test",
                                              "/org/libvirt/test",
@@ -315,6 +316,12 @@ static int testMessageArrayRef(const void *args ATTRIBUTE_UNUSED)
     VIR_FREE(out_int32);
     VIR_FREE(out_str1);
     VIR_FREE(out_str2);
+    for (i = 0; i < out_nstrv1; i++)
+        VIR_FREE(out_strv1[i]);
+    VIR_FREE(out_strv1);
+    for (i = 0; i < out_nstrv2; i++)
+        VIR_FREE(out_strv2[i]);
+    VIR_FREE(out_strv2);
     dbus_message_unref(msg);
     return ret;
 }