nsswitch: Fix memory leak in test_wbc_domain_info()
authorAndreas Schneider <asn@samba.org>
Wed, 22 Jun 2016 06:16:11 +0000 (08:16 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 24 Jun 2016 00:01:19 +0000 (02:01 +0200)
Found by cppcheck.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
nsswitch/libwbclient/tests/wbclient.c

index 380a3dd..41a581e 100644 (file)
@@ -255,21 +255,31 @@ static bool test_wbc_guidtostring(struct torture_context *tctx)
 
 static bool test_wbc_domain_info(struct torture_context *tctx)
 {
-       struct wbcDomainInfo *info;
-       struct wbcInterfaceDetails *details;
+       struct wbcDomainInfo *info = NULL;
+       struct wbcInterfaceDetails *details = NULL;
+       wbcErr ret = false;
 
-       torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
-               "%s", "wbcInterfaceDetails failed");
-       torture_assert_wbc_ok(
-               tctx, wbcDomainInfo(details->netbios_domain, &info),
-               "%s", "wbcDomainInfo failed");
-       wbcFreeMemory(details);
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcInterfaceDetails(&details),
+                                       "%s",
+                                       "wbcInterfaceDetails failed");
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcDomainInfo(details->netbios_domain, &info),
+                                       "%s",
+                                       "wbcDomainInfo failed");
+
+       torture_assert_goto(tctx,
+                           info,
+                           ret,
+                           fail,
+                           "wbcDomainInfo returned NULL pointer");
 
-       torture_assert(tctx, info,
-               "wbcDomainInfo returned NULL pointer");
+       ret = true;
+fail:
+       wbcFreeMemory(details);
        wbcFreeMemory(info);
 
-       return true;
+       return ret;
 }
 
 static bool test_wbc_users(struct torture_context *tctx)