Blame SOURCES/0168-CACHE_REQ-Simplify-_search_ncache_filter.patch

bb7cd1
From 992a6410a3100cc64f9f2ea674fda9151fa5d474 Mon Sep 17 00:00:00 2001
bb7cd1
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
bb7cd1
Date: Mon, 29 May 2017 14:58:33 +0200
bb7cd1
Subject: [PATCH 168/169] CACHE_REQ: Simplify _search_ncache_filter()
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
Let's make the result and input/output argument for
bb7cd1
_search_ncache_filter() and free it inside the function whenever it's
bb7cd1
needed instead of leaving this responsibility for the caller.
bb7cd1
bb7cd1
Related:
bb7cd1
https://pagure.io/SSSD/sssd/issue/3362
bb7cd1
bb7cd1
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
(cherry picked from commit c8193b1602cf44740b59f5dfcdc5330508c0c365)
bb7cd1
---
bb7cd1
 src/responder/common/cache_req/cache_req_search.c | 27 ++++++-----------------
bb7cd1
 1 file changed, 7 insertions(+), 20 deletions(-)
bb7cd1
bb7cd1
diff --git a/src/responder/common/cache_req/cache_req_search.c b/src/responder/common/cache_req/cache_req_search.c
bb7cd1
index 70448a7639bc9f98d380b8edce9d130adfa0ceb2..d3aaa7542ddfd28716fbf9cdcedfeadb649dbaa0 100644
bb7cd1
--- a/src/responder/common/cache_req/cache_req_search.c
bb7cd1
+++ b/src/responder/common/cache_req/cache_req_search.c
bb7cd1
@@ -86,7 +86,6 @@ static void cache_req_search_ncache_add(struct cache_req *cr)
bb7cd1
 
bb7cd1
 static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
bb7cd1
                                               struct cache_req *cr,
bb7cd1
-                                              struct ldb_result *result,
bb7cd1
                                               struct ldb_result **_result)
bb7cd1
 {
bb7cd1
     TALLOC_CTX *tmp_ctx;
bb7cd1
@@ -106,8 +105,6 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
bb7cd1
                         "This request type does not support filtering "
bb7cd1
                         "result by negative cache\n");
bb7cd1
 
bb7cd1
-        *_result = talloc_steal(mem_ctx, result);
bb7cd1
-
bb7cd1
         ret = EOK;
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
@@ -115,11 +112,11 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
bb7cd1
     CACHE_REQ_DEBUG(SSSDBG_TRACE_FUNC, cr,
bb7cd1
                     "Filtering out results by negative cache\n");
bb7cd1
 
bb7cd1
-    msgs = talloc_zero_array(tmp_ctx, struct ldb_message *, result->count);
bb7cd1
+    msgs = talloc_zero_array(tmp_ctx, struct ldb_message *, (*_result)->count);
bb7cd1
     msg_count = 0;
bb7cd1
 
bb7cd1
-    for (size_t i = 0; i < result->count; i++) {
bb7cd1
-        name = sss_get_name_from_msg(cr->domain, result->msgs[i]);
bb7cd1
+    for (size_t i = 0; i < (*_result)->count; i++) {
bb7cd1
+        name = sss_get_name_from_msg(cr->domain, (*_result)->msgs[i]);
bb7cd1
         if (name == NULL) {
bb7cd1
             CACHE_REQ_DEBUG(SSSDBG_CRIT_FAILURE, cr,
bb7cd1
                   "sss_get_name_from_msg() returned NULL, which should never "
bb7cd1
@@ -141,7 +138,7 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
bb7cd1
             goto done;
bb7cd1
         }
bb7cd1
 
bb7cd1
-        msgs[msg_count] = talloc_steal(msgs, result->msgs[i]);
bb7cd1
+        msgs[msg_count] = talloc_steal(msgs, (*_result)->msgs[i]);
bb7cd1
         msg_count++;
bb7cd1
     }
bb7cd1
 
bb7cd1
@@ -157,6 +154,7 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
+    talloc_zfree(*_result);
bb7cd1
     *_result = talloc_steal(mem_ctx, filtered_result);
bb7cd1
     ret = EOK;
bb7cd1
 
bb7cd1
@@ -419,10 +417,8 @@ static void cache_req_search_oob_done(struct tevent_req *subreq)
bb7cd1
 
bb7cd1
 static void cache_req_search_done(struct tevent_req *subreq)
bb7cd1
 {
bb7cd1
-    TALLOC_CTX *tmp_ctx;
bb7cd1
     struct cache_req_search_state *state;
bb7cd1
     struct tevent_req *req;
bb7cd1
-    struct ldb_result *result = NULL;
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
     req = tevent_req_callback_data(subreq, struct tevent_req);
bb7cd1
@@ -431,14 +427,8 @@ static void cache_req_search_done(struct tevent_req *subreq)
bb7cd1
     state->dp_success = state->cr->plugin->dp_recv_fn(subreq, state->cr);
bb7cd1
     talloc_zfree(subreq);
bb7cd1
 
bb7cd1
-    tmp_ctx = talloc_new(NULL);
bb7cd1
-    if (tmp_ctx == NULL) {
bb7cd1
-        ret = ENOMEM;
bb7cd1
-        goto done;
bb7cd1
-    }
bb7cd1
-
bb7cd1
     /* Get result from cache again. */
bb7cd1
-    ret = cache_req_search_cache(tmp_ctx, state->cr, &result);
bb7cd1
+    ret = cache_req_search_cache(state, state->cr, &state->result);
bb7cd1
     if (ret != EOK) {
bb7cd1
         if (ret == ENOENT) {
bb7cd1
             /* Only store entry in negative cache if DP request succeeded
bb7cd1
@@ -451,8 +441,7 @@ static void cache_req_search_done(struct tevent_req *subreq)
bb7cd1
     }
bb7cd1
 
bb7cd1
     /* ret == EOK */
bb7cd1
-    ret = cache_req_search_ncache_filter(state, state->cr, result,
bb7cd1
-                                         &state->result);
bb7cd1
+    ret = cache_req_search_ncache_filter(state, state->cr, &state->result);
bb7cd1
     if (ret != EOK) {
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
@@ -461,8 +450,6 @@ static void cache_req_search_done(struct tevent_req *subreq)
bb7cd1
                     "Returning updated object [%s]\n", state->cr->debugobj);
bb7cd1
 
bb7cd1
 done:
bb7cd1
-    talloc_free(tmp_ctx);
bb7cd1
-
bb7cd1
     if (ret != EOK) {
bb7cd1
         tevent_req_error(req, ret);
bb7cd1
         return;
bb7cd1
-- 
bb7cd1
2.9.4
bb7cd1