From fea79207f34702b4e784af343eba90cac72055b8 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sat, 16 Jan 2016 01:04:51 +0100 Subject: Free more memory --- service_passwords.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/service_passwords.c b/service_passwords.c index bf70770..1a60fc5 100644 --- a/service_passwords.c +++ b/service_passwords.c @@ -108,9 +108,12 @@ static int dn_contains_uid(const char *dn) if (rc != 0 || slapi_valueset_count(uid_values) == 0) { /* empty uid value */ rc = 1; - goto fail1; + goto fail2; } +fail2: + slapi_valueset_free(uid_values); + fail1: slapi_entry_free(entry); @@ -162,16 +165,19 @@ static char* is_service(const char *dn) if (rc != 0 || cn == NULL) { /* no value in cn attribute */ service = NULL; - goto fail1; + goto fail2; } if (*cn == NULL) { service = NULL; - goto fail1; + goto fail2; } service = slapi_ch_strdup((*cn)->bv_val); +fail2: + ber_bvecfree(cn); + fail1: slapi_entry_free(entry); @@ -221,14 +227,18 @@ static int auth(char *dn, struct berval *credentials) rc |= slapi_attr_get_values(attr, &userPasswords); if (rc != 0 || userPasswords == NULL) { rc = 1; - goto fail1; + goto fail2; } /* check password */ rc |= slapi_pw_find(userPasswords, credentials); +fail2: + ber_bvecfree(userPasswords); + fail1: slapi_entry_free(entry); + return rc; } @@ -458,21 +468,28 @@ static int pre_entry(Slapi_PBlock *pb) /* ignore service_password entries */ parent_dn = slapi_dn_parent(result_dn); - if (dn_contains_uid(parent_dn) == 0) { + rc |= dn_contains_uid(parent_dn); + slapi_ch_free_string(&parent_dn); + + if (rc == 0) { rc = -1; goto fail1; } - slapi_ch_free_string(&parent_dn); /* modify the dn of the returned entry */ if (dn_contains_uid(result_dn) == 0) { /* TODO: style */ + new_entry = slapi_entry_dup(entry); + ber_bvfree(new_entry->e_name); + ber_bvfree(new_entry->e_nname); + snprintf(rdn, 254, "cn=%s", service); new_dn = slapi_dn_plus_rdn(result_dn, rdn); - new_entry = slapi_entry_dup(entry); slapi_entry_set_dn(new_entry, new_dn); slapi_ch_free_string(&new_dn); + slapi_pblock_set(pb, SLAPI_SEARCH_RESULT_ENTRY, new_entry); + slapi_entry_free(entry); } fail1: -- cgit v1.2.3-1-g7c22