allocate less

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7630 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-02-15 20:42:58 +00:00
parent 345d5c79ba
commit d54c936938
1 changed files with 6 additions and 11 deletions

View File

@ -141,8 +141,6 @@ static switch_status_t load_config(void)
static void event_handler(switch_event_t *event) static void event_handler(switch_event_t *event)
{ {
char *buf;
size_t len;
uint8_t send = 0; uint8_t send = 0;
if (globals.running != 1) { if (globals.running != 1) {
@ -154,9 +152,6 @@ static void event_handler(switch_event_t *event)
return; return;
} }
buf = (char *) malloc(MULTICAST_BUFFSIZE);
switch_assert(buf);
if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) { if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) {
send = 1; send = 1;
} else if ((globals.event_list[(uint8_t) event->event_id])) { } 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) { switch (event->event_id) {
case SWITCH_EVENT_LOG: case SWITCH_EVENT_LOG:
goto end; return;
default: default:
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", "%s", globals.hostname); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", "%s", globals.hostname);
if (switch_event_serialize(event, &packet, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { 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)); memcpy(buf, &globals.host_hash, sizeof(globals.host_hash));
switch_copy_string(buf + sizeof(globals.host_hash), packet, MULTICAST_BUFFSIZE - sizeof(globals.host_hash)); switch_copy_string(buf + sizeof(globals.host_hash), packet, len - 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_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len); switch_socket_sendto(globals.udp_socket, globals.addr, 0, buf, &len);
switch_safe_free(packet); switch_safe_free(packet);
switch_safe_free(buf);
} }
break; break;
} }
} }
end:
free(buf);
return; return;
} }