diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 5896b66b81..87182742a0 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -145,14 +145,18 @@ static void event_handler(switch_event_t *event) size_t len; uint8_t send = 0; - buf = (char *) malloc(MULTICAST_BUFFSIZE); - switch_assert(buf); + if (globals.running != 1) { + return; + } if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) { /* ignore our own events to avoid ping pong */ return; } + buf = (char *) malloc(MULTICAST_BUFFSIZE); + switch_assert(buf); + if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) { send = 1; } else if ((globals.event_list[(uint8_t) event->event_id])) { @@ -250,8 +254,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown) if (globals.udp_socket) { switch_socket_shutdown(globals.udp_socket, SWITCH_SHUTDOWN_READWRITE); - switch_socket_close(globals.udp_socket); - globals.udp_socket = NULL; } if (globals.running == 1) { @@ -262,6 +264,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown) } } + if (globals.udp_socket) { + switch_socket_close(globals.udp_socket); + globals.udp_socket = NULL; + } + switch_core_hash_destroy(&globals.event_hash); return SWITCH_STATUS_SUCCESS;