summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2016-06-22 08:48:12 +0200
committerAndreas Schneider <asn@cryptomilk.org>2016-06-24 02:01:19 +0200
commit3c9f0815fb0822c7e9521b5526c24addd9f89a34 (patch)
tree0ceb83b9ed1550b8a488e6e5a56f9d9deac12ab8
parente9fabe3a116e0172ab2b77b26bbd0706e51a2a81 (diff)
downloadsamba-3c9f0815fb0822c7e9521b5526c24addd9f89a34.tar.gz
nsswitch: Fix memory leak in test_wbc_groups()
Found by cppcheck. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Uri Simchoni <uri@samba.org>
-rw-r--r--nsswitch/libwbclient/tests/wbclient.c73
1 files changed, 55 insertions, 18 deletions
diff --git a/nsswitch/libwbclient/tests/wbclient.c b/nsswitch/libwbclient/tests/wbclient.c
index a4c1751db7d..94a932f8526 100644
--- a/nsswitch/libwbclient/tests/wbclient.c
+++ b/nsswitch/libwbclient/tests/wbclient.c
@@ -388,43 +388,80 @@ fail:
static bool test_wbc_groups(struct torture_context *tctx)
{
+ wbcErr ret = false;
const char *domain_name = NULL;
uint32_t num_groups;
- const char **groups;
- int i;
- struct wbcInterfaceDetails *details;
+ const char **groups = NULL;
+ uint32_t i;
+ struct wbcInterfaceDetails *details = NULL;
+ char *domain = NULL;
+ char *name = NULL;
+ char *sid_string = NULL;
torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
"%s", "wbcInterfaceDetails failed");
domain_name = talloc_strdup(tctx, details->netbios_domain);
+ torture_assert_goto(tctx,
+ domain_name != NULL,
+ ret,
+ fail,
+ "Failed to allocate domain_name");
wbcFreeMemory(details);
+ details = NULL;
- torture_assert_wbc_ok(tctx, wbcListGroups(domain_name, &num_groups, &groups),
- "wbcListGroups in %s failed", domain_name);
- torture_assert(tctx, !(num_groups > 0 && !groups),
- "wbcListGroups returned invalid results");
+ torture_assert_wbc_ok_goto_fail(tctx,
+ wbcListGroups(domain_name, &num_groups, &groups),
+ "wbcListGroups in %s failed",
+ domain_name);
+ torture_assert_goto(tctx,
+ !(num_groups > 0 && !groups),
+ ret,
+ fail,
+ "wbcListGroups returned invalid results");
for (i=0; i < MIN(num_groups,100); i++) {
-
struct wbcDomainSid sid;
enum wbcSidType name_type;
- char *domain;
- char *name;
- char *sid_string;
- torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, groups[i], &sid, &name_type),
- "wbcLookupName for %s failed", domain_name);
+ torture_assert_wbc_ok_goto_fail(tctx,
+ wbcLookupName(domain_name,
+ groups[i],
+ &sid,
+ &name_type),
+ "wbcLookupName for %s failed",
+ domain_name);
wbcSidToString(&sid, &sid_string);
- torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
- "wbcLookupSid of %s failed", sid_string);
+ torture_assert_wbc_ok_goto_fail(tctx,
+ wbcLookupSid(&sid,
+ &domain,
+ &name,
+ &name_type),
+ "wbcLookupSid of %s failed",
+ sid_string);
+ torture_assert_goto(tctx,
+ name,
+ ret,
+ fail,
+ "wbcLookupSid returned no name");
+
+ wbcFreeMemory(domain);
+ domain = NULL;
+ wbcFreeMemory(name);
+ name = NULL;
wbcFreeMemory(sid_string);
- torture_assert(tctx, name,
- "wbcLookupSid returned no name");
+ sid_string = NULL;
}
+
+ ret = true;
+fail:
+ wbcFreeMemory(details);
wbcFreeMemory(groups);
+ wbcFreeMemory(domain);
+ wbcFreeMemory(name);
+ wbcFreeMemory(sid_string);
- return true;
+ return ret;
}
static bool test_wbc_trusts(struct torture_context *tctx)