From d0eb88089b059bfe2da3bd1a3797b89d69119c29 Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Feb 17 2020 10:37:30 +0000 Subject: sss_ptr_hash: sss_ptr_hash_delete fix/optimization - no reason to skip hash_delete() just because sss_ptr_hash_lookup_internal() failed - avoid excessive lookup if it is not required to free payload Reviewed-by: Pavel Březina --- diff --git a/src/util/sss_ptr_hash.c b/src/util/sss_ptr_hash.c index f8addec..7326244 100644 --- a/src/util/sss_ptr_hash.c +++ b/src/util/sss_ptr_hash.c @@ -331,20 +331,21 @@ void sss_ptr_hash_delete(hash_table_t *table, struct sss_ptr_hash_value *value; hash_key_t table_key; int hret; - void *ptr; + void *payload; if (table == NULL || key == NULL) { return; } - value = sss_ptr_hash_lookup_internal(table, key); - if (value == NULL) { - /* Value not found. */ - return; + if (free_value) { + value = sss_ptr_hash_lookup_internal(table, key); + if (value == NULL) { + free_value = false; + } else { + payload = value->ptr; + } } - ptr = value->ptr; - table_key.type = HASH_KEY_STRING; table_key.str = discard_const_p(char, key); @@ -357,7 +358,7 @@ void sss_ptr_hash_delete(hash_table_t *table, /* Also free the original value if requested. */ if (free_value) { - talloc_free(ptr); + talloc_free(payload); } return;