nsswitch: Fix memory leak in test_wbc_pingdc2()
[sfrench/samba-autobuild/.git] / nsswitch / libwbclient / tests / wbclient.c
index 3bedf960331c734c371cc6c7134f09a3a34c2818..380a3dd02c2cff39a8676e506fee943a2c50a469 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)