Blob Blame History Raw
From f6d20a58183d7a7ab20033a87ddd60798e809f80 Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikhono@redhat.com>
Date: Mon, 28 Jan 2019 19:23:46 +0100
Subject: [PATCH 4/9] providers/proxy: got rid of excessive mem copies
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

There is no need to create copies of strings for temporary storage
in hash_table.

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit 29ac739ee186bab2e3a0111fcc8f43cb70401b42)

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
 src/providers/proxy/proxy_id.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
index 52f7a6424..3e8a43ad7 100644
--- a/src/providers/proxy/proxy_id.c
+++ b/src/providers/proxy/proxy_id.c
@@ -620,24 +620,15 @@ static errno_t remove_duplicate_group_members(TALLOC_CTX *mem_ctx,
 
     for (i=0; i < orig_member_count; ++i) {
         key.type = HASH_KEY_STRING;
-        key.str = talloc_strdup(member_tbl, orig_grp->gr_mem[i]);
-        if (key.str == NULL) {
-            DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
-            ret = ENOMEM;
-            goto done;
-        }
+        key.str = orig_grp->gr_mem[i]; /* hash_enter() makes copy itself */
 
         value.type = HASH_VALUE_PTR;
-        value.ptr = talloc_strdup(member_tbl, orig_grp->gr_mem[i]);
-        if (value.ptr == NULL) {
-            DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
-            ret = ENOMEM;
-            goto done;
-        }
+        /* no need to put copy in hash_table since
+           copy will be created during construction of new grp */
+        value.ptr = orig_grp->gr_mem[i];
 
         ret = hash_enter(member_tbl, &key, &value);
         if (ret != HASH_SUCCESS) {
-            talloc_free(key.str);
             ret = ENOMEM;
             goto done;
         }
-- 
2.21.1