]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] Fix possible leak of the subclass variable in CUSTOM_HASH'es switch_event_rese... 369/head
authorAndrey Volk <andywolk@gmail.com>
Sat, 15 Feb 2020 20:29:38 +0000 (00:29 +0400)
committerAndrey Volk <andywolk@gmail.com>
Sat, 15 Feb 2020 20:29:38 +0000 (00:29 +0400)
src/include/switch_utils.h
src/switch_event.c
src/switch_utils.c

index 5ff584bd0c2a5a2bc413e630193c45fde4cc421c..1c409759083405f32c9088d1185f52b117f3c75e 100644 (file)
@@ -1338,6 +1338,12 @@ SWITCH_DECLARE(void) switch_split_time(const char *exp, int *hour, int *min, int
 */
 SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domain);
 
+SWITCH_DECLARE(void *) switch_calloc(size_t nmemb, size_t size);
+
+#ifdef __clang_analyzer__
+#define calloc switch_calloc
+#endif
+
 /* malloc or DIE macros */
 #ifdef NDEBUG
 #define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%d", __FILE__, __LINE__),abort(), 0), ptr )
index 91e07c6b79923e52e0c3542b8825461517935a38..a29ac78858a32a68ca9cc65766c4ada3298234b5 100644 (file)
@@ -503,7 +503,13 @@ SWITCH_DECLARE(switch_status_t) switch_event_reserve_subclass_detailed(const cha
        subclass->owner = DUP(owner);
        subclass->name = DUP(subclass_name);
 
-       switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass);
+       status = switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass);
+
+       if (status != SWITCH_STATUS_SUCCESS) {
+               free(subclass->owner);
+               free(subclass->name);
+               free(subclass);
+       }
 
 end:
 
index 2e249d65931c01083d047bbea33d17a6b0817acb..e6e4917b1eedb51592934d85d1a4368c16a020ae 100644 (file)
@@ -71,6 +71,11 @@ struct switch_network_list {
        char *name;
 };
 
+SWITCH_DECLARE(void *) switch_calloc(size_t nmemb, size_t size)
+{
+       return calloc(nmemb, size);
+}
+
 #ifndef WIN32
 SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst)
 {