From d54c93693887baa4043e568cf8d68af7f7f7477d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Feb 2008 20:42:58 +0000 Subject: [PATCH] allocate less git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7630 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_event_multicast/mod_event_multicast.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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 87182742a0..14669230c1 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 @@ -141,8 +141,6 @@ static switch_status_t load_config(void) static void event_handler(switch_event_t *event) { - char *buf; - size_t len; uint8_t send = 0; if (globals.running != 1) { @@ -154,9 +152,6 @@ static void event_handler(switch_event_t *event) 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])) { @@ -170,22 +165,22 @@ static void event_handler(switch_event_t *event) switch (event->event_id) { case SWITCH_EVENT_LOG: - goto end; + return; default: switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", "%s", globals.hostname); if (switch_event_serialize(event, &packet, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { + size_t len = strlen(packet) + sizeof(globals.host_hash); + char *buf = malloc(len + 1); + switch_assert(buf); memcpy(buf, &globals.host_hash, sizeof(globals.host_hash)); - switch_copy_string(buf + sizeof(globals.host_hash), packet, MULTICAST_BUFFSIZE - sizeof(globals.host_hash)); - len = strlen(packet) + sizeof(globals.host_hash);; - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT\n--------------------------------\n%s\n", buf); + switch_copy_string(buf + sizeof(globals.host_hash), packet, len - sizeof(globals.host_hash)); switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len); switch_safe_free(packet); + switch_safe_free(buf); } break; } } -end: - free(buf); return; }