Blob Blame History Raw
From dbe1e300171e04cc328a4f31d0bffcac056e7cfa Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <abokovoy@redhat.com>
Date: Mon, 31 Aug 2020 16:53:47 +0300
Subject: [PATCH] idviews: clear intermediate target DN in all cases

When processing a search request, slapi-nis attempts to detect an ID
View lookup. A target DN is modified by extracting an ID view name. This
temporary string is freed in the successful case but left unotouched if
ID View wasn't requested. As a result, small leaks on each search
request accumulate and a memory can get lost.

Resolves: rhbz#1866113

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
---
 src/back-sch.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/back-sch.c b/src/back-sch.c
index 03abbeb..f8b04a3 100644
--- a/src/back-sch.c
+++ b/src/back-sch.c
@@ -1767,6 +1767,7 @@ backend_search_cb(Slapi_PBlock *pb)
 			/* Perform another check, now for rewritten DN */
 			cbdata.target_dn = slapi_sdn_new_dn_byval(target);
 			map_data_foreach_domain(cbdata.state, backend_search_find_set_dn_cb, &cbdata);
+
 			/* Rewritten DN might still be outside of our trees */
 			if (cbdata.answer == TRUE) {
 				slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,
@@ -1774,19 +1775,21 @@ backend_search_cb(Slapi_PBlock *pb)
 						"for \"%s\" with scope %d%s. Filter may get overridden later.\n",
 						cbdata.idview, target, cbdata.strfilter, cbdata.scope,
 						backend_sch_scope_as_string(cbdata.scope));
-			} else {
-				slapi_sdn_free(&cbdata.target_dn);
-				slapi_ch_free_string(&target);
-				slapi_ch_free_string(&cbdata.idview);
+			}
+
+			slapi_sdn_free(&cbdata.target_dn);
+			slapi_ch_free_string(&cbdata.idview);
+
+			if (cbdata.answer == FALSE) {
 				slapi_log_error(SLAPI_LOG_PLUGIN,
 						cbdata.state->plugin_desc->spd_id,
 						"The search base didn't match any of the containers, "
 						"ignoring search\n");
+				slapi_ch_free_string(&target);
 				return 0;
 			}
-		} else {
-			slapi_ch_free_string(&target);
 		}
+		slapi_ch_free_string(&target);
 	}
 	cbdata.answer = FALSE;
 #endif
-- 
2.26.2