nsswitch: Fix memory leak in test_wbc_pingdc()
authorAndreas Schneider <asn@samba.org>
Wed, 22 Jun 2016 05:56:20 +0000 (07:56 +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 a8acf078d3deed2dbe87264725dca551dab34d6a..0ec5a069072e49062f7373343a8725ba08ff4315 100644 (file)
@@ -79,28 +79,38 @@ static bool test_wbc_ping(struct torture_context *tctx)
 
 static bool test_wbc_pingdc(struct torture_context *tctx)
 {
-       struct wbcInterfaceDetails *details;
+       struct wbcInterfaceDetails *details = NULL;
+       wbcErr ret = false;
 
-       torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_DOMAIN_NOT_FOUND,
-                                "%s", "wbcPingDc failed");
-       torture_assert_wbc_ok(tctx, wbcPingDc(NULL, NULL),
+       torture_assert_wbc_equal_goto_fail(tctx,
+                                          wbcPingDc("random_string", NULL),
+                                          WBC_ERR_DOMAIN_NOT_FOUND,
+                                          "%s",
+                                          "wbcPingDc failed");
+       torture_assert_wbc_ok_goto_fail(tctx, wbcPingDc(NULL, NULL),
                "%s", "wbcPingDc failed");
 
-       torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
+       torture_assert_wbc_ok_goto_fail(tctx, wbcInterfaceDetails(&details),
                "%s", "wbcInterfaceDetails failed");
-       torture_assert(tctx, details,
+       torture_assert_goto(tctx, details, ret, fail,
                       "wbcInterfaceDetails returned NULL pointer");
-       torture_assert(tctx, details->netbios_domain,
+       torture_assert_goto(tctx, details->netbios_domain, ret, fail,
                       "wbcInterfaceDetails returned NULL netbios_domain");
 
-       torture_assert_wbc_ok(tctx, wbcPingDc(details->netbios_domain, NULL),
-               "wbcPingDc(%s) failed", details->netbios_domain);
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcPingDc(details->netbios_domain, NULL),
+                                       "wbcPingDc(%s) failed",
+                                       details->netbios_domain);
 
-       torture_assert_wbc_ok(tctx, wbcPingDc("BUILTIN", NULL),
-               "%s", "wbcPingDc(BUILTIN) failed");
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcPingDc("BUILTIN", NULL),
+                                       "%s",
+                                       "wbcPingDc(BUILTIN) failed");
 
+       ret = true;
+fail:
        wbcFreeMemory(details);
-       return true;
+       return ret;
 }
 
 static bool test_wbc_pingdc2(struct torture_context *tctx)