Fix Memory Leak in testMessageArrayRef()

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>
This commit is contained in:
Nehal J Wani 2014-03-31 03:05:56 +05:30 committed by Eric Blake
parent 14d7fcc23a
commit 968aae48c9

View 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;
}