diff --git a/src/switch_core_hash.c b/src/switch_core_hash.c index 1655aac726..70102ce957 100644 --- a/src/switch_core_hash.c +++ b/src/switch_core_hash.c @@ -57,20 +57,28 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t **hash) SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_auto_free(switch_hash_t *hash, const char *key, const void *data) { - int r = 0; + char *dkey = strdup(key); - r = switch_hashtable_insert_destructor(hash, strdup(key), (void *)data, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE | HASHTABLE_DUP_CHECK, NULL); + if (switch_hashtable_insert_destructor(hash, dkey, (void *)data, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE | HASHTABLE_DUP_CHECK, NULL)) { + return SWITCH_STATUS_SUCCESS; + } - return r ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; + switch_safe_free(dkey); + + return SWITCH_STATUS_FALSE; } SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_destructor(switch_hash_t *hash, const char *key, const void *data, hashtable_destructor_t destructor) { - int r = 0; + char *dkey = strdup(key); - r = switch_hashtable_insert_destructor(hash, strdup(key), (void *)data, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_DUP_CHECK, destructor); + if (switch_hashtable_insert_destructor(hash, dkey, (void *)data, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_DUP_CHECK, destructor)) { + return SWITCH_STATUS_SUCCESS; + } - return r ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; + switch_safe_free(dkey); + + return SWITCH_STATUS_FALSE; } SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t *hash, const char *key, const void *data, switch_mutex_t *mutex)