From 0799c446809a7ae239864e69995849431cd2cb00 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Dec 2001 07:35:57 +0000 Subject: paranoia fixes in based ldap routines for potential memory leaks (This used to be commit 13b933104e1389608e4831ca47dd8106ea0c60a5) --- source3/libads/ldap.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'source3/libads') diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 251a4a6958..5b391f1282 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -446,13 +446,14 @@ char *ads_pull_string(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, void *msg, const char *field) { char **values; - char *ret; + char *ret = NULL; values = ldap_get_values(ads->ld, msg, field); - - if (!values || !values[0]) return NULL; - - ret = talloc_strdup(mem_ctx, values[0]); + if (!values) return NULL; + + if (values[0]) { + ret = talloc_strdup(mem_ctx, values[0]); + } ldap_value_free(values); return ret; } @@ -466,8 +467,11 @@ BOOL ads_pull_uint32(ADS_STRUCT *ads, char **values; values = ldap_get_values(ads->ld, msg, field); - - if (!values || !values[0]) return False; + if (!values) return False; + if (!values[0]) { + ldap_value_free(values); + return False; + } *v = atoi(values[0]); ldap_value_free(values); @@ -481,13 +485,15 @@ BOOL ads_pull_sid(ADS_STRUCT *ads, void *msg, const char *field, DOM_SID *sid) { struct berval **values; - BOOL ret; + BOOL ret = False; values = ldap_get_values_len(ads->ld, msg, field); - if (!values || !values[0]) return False; + if (!values) return False; - ret = sid_parse(values[0]->bv_val, values[0]->bv_len, sid); + if (values[0]) { + ret = sid_parse(values[0]->bv_val, values[0]->bv_len, sid); + } ldap_value_free_len(values); return ret; -- cgit