From 781180ff48b65d308063ecbaf49ccfd8f964b884 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 23 Apr 2021 00:23:39 +0300 Subject: [PATCH] [Core] scan-build: memory leak in switch_xml_user_cache() --- src/switch_xml.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/switch_xml.c b/src/switch_xml.c index 97ed4b563d..b70f6bfe74 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -2095,10 +2095,9 @@ static void switch_xml_user_cache(const char *key, const char *user_name, const switch_safe_free(expires_lookup); } if (expires) { - char *expires_val = switch_must_malloc(1024); - if (sprintf(expires_val, "%ld", (long)expires)) { - switch_core_hash_insert(CACHE_EXPIRES_HASH, mega_key, expires_val); - } else { + char *expires_val = (char *)switch_core_hash_insert_alloc(CACHE_EXPIRES_HASH, mega_key, 22); + if (!snprintf(expires_val, 22, "%ld", (long)expires)) { + switch_core_hash_delete(CACHE_EXPIRES_HASH, mega_key); switch_safe_free(expires_val); } }