Blame SOURCES/cyrus-imapd-memory_leak_on_cleanup_2.patch

020be8
diff --git a/ptclient/ldap.c b/ptclient/ldap.c
020be8
index 7e48879..dafa724 100644
020be8
--- a/ptclient/ldap.c
020be8
+++ b/ptclient/ldap.c
020be8
@@ -932,7 +932,7 @@ static int ptsmodule_get_dn(
020be8
     {
020be8
         rc = ptsmodule_expand_tokens(ptsm->filter, canon_id, NULL, &filter);
020be8
         if (rc != PTSM_OK)
020be8
-            return rc;
020be8
+            goto done;
020be8
 
020be8
         if (ptsm->domain_base_dn && ptsm->domain_base_dn[0] != '\0' && (strrchr(canon_id, '@') != NULL)) {
020be8
             syslog(LOG_DEBUG, "Attempting to get domain for %s from %s", canon_id, ptsm->domain_base_dn);
020be8
@@ -955,19 +955,23 @@ static int ptsmodule_get_dn(
020be8
                     ldap_unbind(ptsm->ld);
020be8
                     ptsm->ld = NULL;
020be8
                     syslog(LOG_ERR, "LDAP not available: %s", ldap_err2string(rc));
020be8
-                    return PTSM_RETRY;
020be8
+                    rc = PTSM_RETRY;
020be8
+                    goto done;
020be8
                 }
020be8
 
020be8
                 syslog(LOG_ERR, "LDAP search for domain failed: %s", ldap_err2string(rc));
020be8
-                return PTSM_FAIL;
020be8
+                rc = PTSM_FAIL;
020be8
+                goto done;
020be8
             }
020be8
 
020be8
             if (ldap_count_entries(ptsm->ld, res) < 1) {
020be8
                 syslog(LOG_ERR, "No domain %s found", domain);
020be8
-                return PTSM_FAIL;
020be8
+                rc = PTSM_FAIL;
020be8
+                goto done;
020be8
             } else if (ldap_count_entries(ptsm->ld, res) > 1) {
020be8
                 syslog(LOG_ERR, "Multiple domains %s found", domain);
020be8
-                return PTSM_FAIL;
020be8
+                rc = PTSM_FAIL;
020be8
+                goto done;
020be8
             } else {
020be8
                 if ((entry = ldap_first_entry(ptsm->ld, res)) != NULL) {
020be8
                     if ((vals = ldap_get_values(ptsm->ld, entry, ptsm->domain_result_attribute)) != NULL) {
020be8
@@ -982,7 +986,7 @@ static int ptsmodule_get_dn(
020be8
                     }
020be8
 
020be8
                     if (rc != PTSM_OK) {
020be8
-                        return rc;
020be8
+                        goto done;
020be8
                     } else {
020be8
                         base = xstrdup(ptsm->base);
020be8
                         syslog(LOG_DEBUG, "Continuing with ptsm->base: %s", ptsm->base);
020be8
@@ -993,23 +997,23 @@ static int ptsmodule_get_dn(
020be8
         } else {
020be8
             rc = ptsmodule_expand_tokens(ptsm->base, canon_id, NULL, &base);
020be8
             if (rc != PTSM_OK)
020be8
-                return rc;
020be8
+                goto done;
020be8
         }
020be8
 
020be8
         rc = ldap_search_st(ptsm->ld, base, ptsm->scope, filter, attrs, 0, &(ptsm->timeout), &res;;
020be8
 
020be8
         if (rc != LDAP_SUCCESS) {
020be8
             syslog(LOG_DEBUG, "Searching %s with %s failed", base, base);
020be8
-            free(filter);
020be8
-            free(base);
020be8
 
020be8
             if (rc == LDAP_SERVER_DOWN) {
020be8
                 ldap_unbind(ptsm->ld);
020be8
                 ptsm->ld = NULL;
020be8
-                return PTSM_RETRY;
020be8
+                rc = PTSM_RETRY;
020be8
+                goto done;
020be8
             }
020be8
 
020be8
-            return PTSM_FAIL;
020be8
+            rc = PTSM_FAIL;
020be8
+            goto done;
020be8
         }
020be8
 
020be8
         free(filter);
020be8
@@ -1035,6 +1039,13 @@ static int ptsmodule_get_dn(
020be8
     }
020be8
 
020be8
     return (*ret ? PTSM_OK : PTSM_FAIL);
020be8
+
020be8
+ done:
020be8
+    if (filter)
020be8
+        free(filter);
020be8
+    if (base)
020be8
+        free(base);
020be8
+    return rc;
020be8
 }
020be8
 
020be8
 
020be8
@@ -1344,7 +1355,7 @@ static int ptsmodule_make_authstate_group(
020be8
     rc = ptsmodule_connect();
020be8
     if (rc != PTSM_OK) {
020be8
         *reply = "ptsmodule_connect() failed";
020be8
-        goto done;;
020be8
+        goto done;
020be8
     }
020be8
 
020be8
     rc = ptsmodule_expand_tokens(ptsm->group_filter, canon_id+6, NULL, &filter);