summaryrefslogtreecommitdiffstats
path: root/daemons/ipa-kdb/ipa_kdb_common.c
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2013-02-12 11:59:22 +0100
committerMartin Kosek <mkosek@redhat.com>2013-02-14 10:09:48 +0100
commit93ea8a6ac311d7365b093b3449b281bbfa0911ab (patch)
treed35eb678374bbb6a58afc5b64878ad3ad11f6048 /daemons/ipa-kdb/ipa_kdb_common.c
parentb8079f9ed4ba9632c77fa973aa2247a4d30434fa (diff)
downloadfreeipa-93ea8a6ac311d7365b093b3449b281bbfa0911ab.tar.gz
freeipa-93ea8a6ac311d7365b093b3449b281bbfa0911ab.tar.xz
freeipa-93ea8a6ac311d7365b093b3449b281bbfa0911ab.zip
ipa-kdb: remove memory leaks
All known memory leaks caused by unfreed allocated memory or unfreed LDAP results (which should be also done after unsuccessful searches) are fixed. https://fedorahosted.org/freeipa/ticket/3413
Diffstat (limited to 'daemons/ipa-kdb/ipa_kdb_common.c')
-rw-r--r--daemons/ipa-kdb/ipa_kdb_common.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/daemons/ipa-kdb/ipa_kdb_common.c b/daemons/ipa-kdb/ipa_kdb_common.c
index e04bae667..121b8096d 100644
--- a/daemons/ipa-kdb/ipa_kdb_common.c
+++ b/daemons/ipa-kdb/ipa_kdb_common.c
@@ -172,7 +172,7 @@ krb5_error_code ipadb_simple_search(struct ipadb_context *ipactx,
/* first test if we need to retry to connect */
if (ret != 0 &&
ipadb_need_retry(ipactx, ret)) {
-
+ ldap_msgfree(*res);
ret = ldap_search_ext_s(ipactx->lcontext, basedn, scope,
filter, attrs, 0, NULL, NULL,
&std_timeout, LDAP_NO_LIMIT,
@@ -283,6 +283,7 @@ krb5_error_code ipadb_deref_search(struct ipadb_context *ipactx,
int times;
int ret;
int c, i;
+ bool retry;
for (c = 0; deref_attr_names[c]; c++) {
/* count */ ;
@@ -315,7 +316,8 @@ krb5_error_code ipadb_deref_search(struct ipadb_context *ipactx,
/* retry once if connection errors (tot. max. 2 tries) */
times = 2;
ret = LDAP_SUCCESS;
- while (!ipadb_need_retry(ipactx, ret) && times > 0) {
+ retry = true;
+ while (retry) {
times--;
ret = ldap_search_ext_s(ipactx->lcontext, base_dn,
scope, filter,
@@ -323,11 +325,18 @@ krb5_error_code ipadb_deref_search(struct ipadb_context *ipactx,
ctrl, NULL,
&std_timeout, LDAP_NO_LIMIT,
res);
+ retry = !ipadb_need_retry(ipactx, ret) && times > 0;
+
+ if (retry) {
+ /* Free result before next try */
+ ldap_msgfree(*res);
+ }
}
kerr = ipadb_simple_ldap_to_kerr(ret);
done:
+ ldap_control_free(ctrl[0]);
ldap_memfree(derefval.bv_val);
free(ds);
return kerr;