Blame SOURCES/cyrus-imapd-memory_leak_on_cleanup.patch

020be8
From acfc393638ad1b81a4234173b060bb63907ee52c Mon Sep 17 00:00:00 2001
020be8
From: Pavel Zhukov <pzhukov@redhat.com>
020be8
Date: Mon, 1 Oct 2018 15:51:01 +0200
020be8
Subject: [PATCH] Replace simple return with cleanup flow
020be8
020be8
Make cleanup more consistence to prevent leaks of memory pointed by
020be8
filter/base/res
020be8
---
020be8
 ptclient/ldap.c | 17 ++++++++++-------
020be8
 1 file changed, 10 insertions(+), 7 deletions(-)
020be8
020be8
diff --git a/ptclient/ldap.c b/ptclient/ldap.c
020be8
index 0b82d2c6b..65bae7bd6 100644
020be8
--- a/ptclient/ldap.c
020be8
+++ b/ptclient/ldap.c
020be8
@@ -1388,13 +1388,14 @@ static int ptsmodule_make_authstate_group(
020be8
 
020be8
     if (strncmp(canon_id, "group:", 6))  { // Sanity check
020be8
         *reply = "not a group identifier";
020be8
-        return PTSM_FAIL;
020be8
+        rc = PTSM_FAIL;
020be8
+        goto done;
020be8
     }
020be8
 
020be8
     rc = ptsmodule_connect();
020be8
     if (rc != PTSM_OK) {
020be8
         *reply = "ptsmodule_connect() failed";
020be8
-        return rc;
020be8
+        goto done;;
020be8
     }
020be8
 
020be8
     rc = ptsmodule_expand_tokens(ptsm->group_filter, canon_id+6, NULL, &filter);
020be8
@@ -1425,17 +1426,19 @@ static int ptsmodule_make_authstate_group(
020be8
 
020be8
         if (rc != LDAP_SUCCESS) {
020be8
             syslog(LOG_DEBUG, "(groups) Result from domain query not OK");
020be8
-            return rc;
020be8
+            goto done;
020be8
         } else {
020be8
             syslog(LOG_DEBUG, "(groups) Result from domain query OK");
020be8
         }
020be8
 
020be8
         if (ldap_count_entries(ptsm->ld, res) < 1) {
020be8
             syslog(LOG_ERR, "(groups) 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, "(groups) Multiple domains %s found", domain);
020be8
-            return PTSM_FAIL;
020be8
+            rc = PTSM_FAIL;
020be8
+            goto done;
020be8
         } else {
020be8
             syslog(LOG_DEBUG, "(groups) Domain %s found", domain);
020be8
             if ((entry = ldap_first_entry(ptsm->ld, res)) != NULL) {
020be8
@@ -1452,7 +1455,7 @@ static int ptsmodule_make_authstate_group(
020be8
                 }
020be8
 
020be8
                 if (rc != PTSM_OK) {
020be8
-                    return rc;
020be8
+                    goto done;
020be8
                 } else {
020be8
                     base = xstrdup(ptsm->group_base);
020be8
                     syslog(LOG_DEBUG, "Continuing with ptsm->group_base: %s", ptsm->group_base);
020be8
@@ -1462,7 +1465,7 @@ static int ptsmodule_make_authstate_group(
020be8
     } else {
020be8
         rc = ptsmodule_expand_tokens(ptsm->group_base, canon_id, NULL, &base);
020be8
         if (rc != PTSM_OK)
020be8
-            return rc;
020be8
+            goto done;
020be8
     }
020be8
 
020be8
     syslog(LOG_DEBUG, "(groups) about to search %s for %s", base, filter);