summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOsier Yang <jyang@redhat.com>2011-06-29 10:47:54 +0800
committerOsier Yang <jyang@redhat.com>2011-06-29 10:47:54 +0800
commita2753079da211930acb1106f7bebd25fb45f7aec (patch)
treec4e30bf42863ea9e04622d53ae91a1e485cca935
parentconf: Fix memory leak in virNetworkDNSDefFormat (diff)
downloadlibvirt-a2753079da211930acb1106f7bebd25fb45f7aec.tar.gz
libvirt-a2753079da211930acb1106f7bebd25fb45f7aec.tar.bz2
libvirt-a2753079da211930acb1106f7bebd25fb45f7aec.zip
tests: Fix memory leak in virnetmessagetest
Detected when playing with "make -C tests valgrind".
-rw-r--r--tests/virnetmessagetest.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c
index e707b677c..a378ed535 100644
--- a/tests/virnetmessagetest.c
+++ b/tests/virnetmessagetest.c
@@ -167,6 +167,7 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED)
{
virNetMessageError err;
static virNetMessage msg;
+ int ret = -1;
static const char expect[] = {
0x00, 0x00, 0x00, 0x74, /* Length */
0x11, 0x22, 0x33, 0x44, /* Program */
@@ -204,19 +205,21 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED)
err.code = VIR_ERR_INTERNAL_ERROR;
err.domain = VIR_FROM_RPC;
+ err.level = VIR_ERR_ERROR;
+
if (VIR_ALLOC(err.message) < 0)
- return -1;
+ goto cleanup;
*err.message = strdup("Hello World");
- err.level = VIR_ERR_ERROR;
if (VIR_ALLOC(err.str1) < 0)
- return -1;
+ goto cleanup;
*err.str1 = strdup("One");
if (VIR_ALLOC(err.str2) < 0)
- return -1;
+ goto cleanup;
*err.str2 = strdup("Two");
if (VIR_ALLOC(err.str3) < 0)
- return -1;
+ goto cleanup;
*err.str3 = strdup("Three");
+
err.int1 = 1;
err.int2 = 2;
@@ -228,29 +231,43 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED)
msg.header.status = VIR_NET_ERROR;
if (virNetMessageEncodeHeader(&msg) < 0)
- return -1;
+ goto cleanup;
if (virNetMessageEncodePayload(&msg, (xdrproc_t)xdr_virNetMessageError, &err) < 0)
- return -1;
+ goto cleanup;
if (ARRAY_CARDINALITY(expect) != msg.bufferLength) {
VIR_DEBUG("Expect message length %zu got %zu",
sizeof(expect), msg.bufferLength);
- return -1;
+ goto cleanup;
}
if (msg.bufferOffset != 0) {
VIR_DEBUG("Expect message offset 0 got %zu",
msg.bufferOffset);
- return -1;
+ goto cleanup;
}
if (memcmp(expect, msg.buffer, sizeof(expect)) != 0) {
virtTestDifferenceBin(stderr, expect, msg.buffer, sizeof(expect));
- return -1;
- }
-
- return 0;
+ goto cleanup;
+ }
+
+ ret = 0;
+cleanup:
+ if (err.message)
+ VIR_FREE(*err.message);
+ if (err.str1)
+ VIR_FREE(*err.str1);
+ if (err.str2)
+ VIR_FREE(*err.str2);
+ if (err.str3)
+ VIR_FREE(*err.str3);
+ VIR_FREE(err.message);
+ VIR_FREE(err.str1);
+ VIR_FREE(err.str2);
+ VIR_FREE(err.str3);
+ return ret;
}
static int testMessagePayloadDecode(const void *args ATTRIBUTE_UNUSED)