]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] scan-build: memory leak in switch_xml_user_cache()
authorAndrey Volk <andywolk@gmail.com>
Thu, 22 Apr 2021 21:23:39 +0000 (00:23 +0300)
committerAndrey Volk <andywolk@gmail.com>
Tue, 19 Oct 2021 17:30:17 +0000 (20:30 +0300)
src/switch_xml.c

index 97ed4b563de90350c659fbcd79d5c8ef85bb8343..b70f6bfe7469258d90bcd2b1f09fda65be849689 100644 (file)
@@ -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);
                }
        }