Blame SOURCES/cyrus-imapd-memory_leak_on_cleanup.patch

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