nsswitch: Fix memory leak in test_wbc_pingdc2()
authorAndreas Schneider <asn@samba.org>
Wed, 22 Jun 2016 06:04:53 +0000 (08:04 +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 3bedf96..380a3dd 100644 (file)
@@ -115,35 +115,55 @@ fail:
 
 static bool test_wbc_pingdc2(struct torture_context *tctx)
 {
-       struct wbcInterfaceDetails *details;
+       struct wbcInterfaceDetails *details = NULL;
        char *name = NULL;
+       wbcErr ret = false;
 
-       torture_assert_wbc_equal(tctx, wbcPingDc2("random_string", NULL, &name),
-                                WBC_ERR_DOMAIN_NOT_FOUND, "%s",
-                                "wbcPingDc2 failed");
-       torture_assert_wbc_ok(tctx, wbcPingDc2(NULL, NULL, &name), "%s",
-                             "wbcPingDc2 failed");
-
+       torture_assert_wbc_equal_goto_fail(tctx,
+                                          wbcPingDc2("random_string", NULL, &name),
+                                          WBC_ERR_DOMAIN_NOT_FOUND,
+                                          "%s",
+                                          "wbcPingDc2 failed");
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcPingDc2(NULL, NULL, &name),
+                                       "%s",
+                                       "wbcPingDc2 failed");
        wbcFreeMemory(name);
+       name = NULL;
 
-       torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
-               "%s", "wbcInterfaceDetails failed");
-       torture_assert(tctx, details,
-                      "wbcInterfaceDetails returned NULL pointer");
-       torture_assert(tctx, details->netbios_domain,
-                      "wbcInterfaceDetails returned NULL netbios_domain");
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcInterfaceDetails(&details),
+                                       "%s",
+                                       "wbcInterfaceDetails failed");
+       torture_assert_goto(tctx,
+                           details,
+                           ret,
+                           fail,
+                           "wbcInterfaceDetails returned NULL pointer");
+       torture_assert_goto(tctx,
+                           details->netbios_domain,
+                           ret,
+                           fail,
+                           "wbcInterfaceDetails returned NULL netbios_domain");
 
-       torture_assert_wbc_ok(tctx, wbcPingDc2(details->netbios_domain, NULL, &name),
-               "wbcPingDc2(%s) failed", details->netbios_domain);
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcPingDc2(details->netbios_domain, NULL, &name),
+                                       "wbcPingDc2(%s) failed",
+                                       details->netbios_domain);
        wbcFreeMemory(name);
+       name = NULL;
 
-       torture_assert_wbc_ok(tctx, wbcPingDc2("BUILTIN", NULL, &name),
-               "%s", "wbcPingDc2(BUILTIN) failed");
-       wbcFreeMemory(name);
+       torture_assert_wbc_ok_goto_fail(tctx,
+                                       wbcPingDc2("BUILTIN", NULL, &name),
+                                       "%s",
+                                       "wbcPingDc2(BUILTIN) failed");
 
+       ret = true;
+fail:
+       wbcFreeMemory(name);
        wbcFreeMemory(details);
 
-       return true;
+       return ret;
 }
 
 static bool test_wbc_library_details(struct torture_context *tctx)