]> git.ipfire.org Git - thirdparty/freeswitch.git/blobdiff - src/switch_event.c
[core] Coverity fixes
[thirdparty/freeswitch.git] / src / switch_event.c
index a8ba532d19acb96bd524ab504a96eb1948b7dd03..02a6f8150573fb2ff50a28a6d86efd4c1fd6003a 100644 (file)
@@ -651,7 +651,6 @@ SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max)
 {
        switch_threadattr_t *thd_attr;
        uint32_t index = 0;
-       int launched = 0;
        uint32_t sanity = 200;
 
        switch_memory_pool_t *pool = RUNTIME_POOL;
@@ -682,7 +681,6 @@ SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max)
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Create additional event dispatch thread %d\n", index);
                }
-               launched++;
        }
 
        SOFT_MAX_DISPATCH = index;
@@ -1246,7 +1244,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_header_string_nodup(switch_even
 SWITCH_DECLARE(switch_status_t) switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
 {
        if (data) {
-               return switch_event_base_add_header(event, stack, header_name, (stack & SWITCH_STACK_NODUP) ? (char *)data : DUP(data));
+               return switch_event_base_add_header(event, stack, header_name, DUP(data));
        }
        return SWITCH_STATUS_GENERR;
 }
@@ -1909,6 +1907,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
                data = (char *) malloc(2048);
                if (!data) {
                        va_end(ap);
+                       switch_xml_free(xml);
+
                        return NULL;
                }
                ret = vsnprintf(data, 2048, fmt, ap);
@@ -1918,6 +1918,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
 #ifndef HAVE_VASPRINTF
                        free(data);
 #endif
+                       switch_xml_free(xml);
+
                        return NULL;
                }
        }
@@ -2069,15 +2071,18 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit
                switch_mutex_lock(CUSTOM_HASH_MUTEX);
 
                if (!(subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
-                       switch_event_reserve_subclass_detailed(id, subclass_name);
-                       subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name);
-                       subclass->bind = 1;
+                       if (switch_event_reserve_subclass_detailed(id, subclass_name) == SWITCH_STATUS_SUCCESS) {
+                               if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
+                                       subclass->bind = 1;
+                               }
+                       }
                }
 
                switch_mutex_unlock(CUSTOM_HASH_MUTEX);
 
                if (!subclass) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not reserve subclass. '%s'\n", subclass_name);
+
                        return SWITCH_STATUS_FALSE;
                }
        }
@@ -2092,6 +2097,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit
                if (subclass_name) {
                        event_node->subclass_name = DUP(subclass_name);
                }
+
                event_node->callback = callback;
                event_node->user_data = user_data;
 
@@ -2950,14 +2956,17 @@ static void ecd_deliver(event_channel_data_t **ecdP)
                int x_argc = switch_separate_string_string(key, (char*) sep, x_argv, SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS);
                char buf[1024];
                int i, r;
+
                for(i=x_argc - 1; i > 0; i--) {
                        int z;
+
                        memset(buf, 0, 1024);
-                       sprintf(buf, "%s", x_argv[0]);
+                       switch_snprintf(buf, sizeof(buf), "%s", x_argv[0]);
                        for(z=1; z < i; z++) {
                                strcat(buf, sep);
-                               strcat(buf, x_argv[z]);
+                               strncat(buf, x_argv[z], sizeof(buf) - strlen(buf) - 1);
                        }
+
                        r = _switch_event_channel_broadcast(buf, ecd->event_channel, ecd->json, ecd->key, ecd->id);
                        t += r;
                        if (r && switch_core_test_flag(SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE)) {
@@ -2966,11 +2975,13 @@ static void ecd_deliver(event_channel_data_t **ecdP)
                }
        } else {
                char *p = NULL;
+
                if ((p = strchr(key, '.'))) {
                        *p = '\0';
                        t += _switch_event_channel_broadcast(key, ecd->event_channel, ecd->json, ecd->key, ecd->id);
                }
        }
+
        switch_safe_free(key);
 
        t += _switch_event_channel_broadcast(SWITCH_EVENT_CHANNEL_GLOBAL, ecd->event_channel, ecd->json, ecd->key, ecd->id);
@@ -2978,6 +2989,7 @@ static void ecd_deliver(event_channel_data_t **ecdP)
        if(t == 0) {
                if (switch_core_test_flag(SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON)) {
                        char *json = cJSON_Print(ecd->json);
+
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no subscribers for %s , %s => %s\n", ecd->event_channel, ecd->key, json);
                        switch_safe_free(json);
                } else {