]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10749: [mod_amqp] Crash on unload after mod_amqp reloaded with command + incorrec...
authorBrian West <brian@freeswitch.org>
Wed, 3 Jan 2018 00:38:45 +0000 (18:38 -0600)
committerMuteesa Fred <muteesafred@hotmail.com>
Tue, 24 Jul 2018 07:21:38 +0000 (07:21 +0000)
src/mod/event_handlers/mod_amqp/mod_amqp_command.c
src/mod/event_handlers/mod_amqp/mod_amqp_producer.c
src/mod/event_handlers/mod_amqp/mod_amqp_utils.c

index 851f52c46f0bee08a0bfd026ef11e894e172dc4a..dba6d20eb0cadcb0c34a5520b5aca75b63fc77b9 100644 (file)
@@ -298,13 +298,13 @@ void * SWITCH_THREAD_FUNC mod_amqp_command_thread(switch_thread_t *thread, void
                                                                  amqp_empty_table);
 #endif
 
-                       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Checking for command exchange")) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile[%s] failed to create missing command exchange", profile->name);
+                       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Checking for command exchange\n")) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile[%s] failed to create missing command exchange\n", profile->name);
                                continue;
                        }
 
                        /* Ensure we have a queue */
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating command queue");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating command queue\n");
                        recv_queue = amqp_queue_declare(profile->conn_active->state, // state
                                                                                        1,                           // channel
                                                                                        profile->queue ? amqp_cstring_bytes(profile->queue) : amqp_empty_bytes, // queue name
@@ -312,7 +312,7 @@ void * SWITCH_THREAD_FUNC mod_amqp_command_thread(switch_thread_t *thread, void
                                                                                        0, 1,                        // exclusive, auto-delete
                                                                                        amqp_empty_table);           // args
 
-                       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Declaring queue")) {
+                       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Declaring queue\n")) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile[%s] failed to connect with code(%d), sleeping for %dms\n",
                                                                  profile->name, status, profile->reconnect_interval_ms);
                                switch_sleep(profile->reconnect_interval_ms * 1000);
index 0c3bc4e22e33b6e0f825fb7791fc5e55bf1675b6..940578b7cdc39fd893f9daed833b9cba5dc60770 100644 (file)
@@ -249,6 +249,7 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
                        } else if (!strncmp(var, "content-type", 12)) {
                                content_type = switch_core_strdup(profile->pool, val);
                        } else if (!strncmp(var, "format_fields", 13)) {
+                               char *tmp;
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "amqp format fields : %s\n", val);
                                if ((format_fields_size = mod_amqp_count_chars(val, ',')) >= MAX_ROUTING_KEY_FORMAT_FIELDS) {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "You can have only %d routing fields in the routing key.\n",
@@ -257,9 +258,11 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
                                }
 
                                /* increment size because the count returned the number of separators, not number of fields */
+                               tmp = strdup(val);
                                format_fields_size++;
-                               switch_separate_string(val, ',', format_fields, MAX_ROUTING_KEY_FORMAT_FIELDS);
+                               switch_separate_string(tmp, ',', format_fields, MAX_ROUTING_KEY_FORMAT_FIELDS);
                                format_fields[format_fields_size] = NULL;
+                               free(tmp);
                        } else if (!strncmp(var, "event_filter", 12)) {
                                /* Parse new events */
                                profile->event_subscriptions = switch_separate_string(val, ',', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -343,7 +346,7 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
                                                  amqp_empty_table);
 #endif
 
-       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Declaring exchange")) {
+       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Declaring exchange\n")) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile[%s] failed to create exchange\n", profile->name);
                goto err;
        }
index bd0289ca8f20fb7a6ff2753408175fb6ce982151..9f0ed3ffd0f661b2d76839c64ba705a8d317606a 100644 (file)
@@ -97,6 +97,31 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload)
                return SWITCH_STATUS_FALSE;
        }
 
+       if (reload) {
+               switch_hash_index_t *hi;
+               mod_amqp_producer_profile_t *producer;
+               mod_amqp_command_profile_t *command;
+               mod_amqp_logging_profile_t *logging;
+
+               switch_event_unbind_callback(mod_amqp_producer_event_handler);
+
+               while ((hi = switch_core_hash_first(mod_amqp_globals.producer_hash))) {
+                       switch_core_hash_this(hi, NULL, NULL, (void **)&producer);
+                       mod_amqp_producer_destroy(&producer);
+               }
+               while ((hi = switch_core_hash_first(mod_amqp_globals.command_hash))) {
+                       switch_core_hash_this(hi, NULL, NULL, (void **)&command);
+                       mod_amqp_command_destroy(&command);
+               }
+
+               switch_log_unbind_logger(mod_amqp_logging_recv);
+
+               while ((hi = switch_core_hash_first(mod_amqp_globals.logging_hash))) {
+                       switch_core_hash_this(hi, NULL, NULL, (void **)&logging);
+                       mod_amqp_logging_destroy(&logging);
+               }
+       }
+
        if ((profiles = switch_xml_child(cfg, "producers"))) {
                if ((profile = switch_xml_child(profiles, "profile"))) {
                        for (; profile; profile = profile->next)        {