refactor mod_event_socket so it uses switch_log functions to duplicate and free log nodes while it uses them internally (fix bad ptr for userdata on event socket listeners)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14598 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Mathieu Rene 2009-08-22 19:26:58 +00:00
parent 35947acdda
commit 5abd10c0c3
3 changed files with 31 additions and 16 deletions

View File

@ -143,6 +143,10 @@ SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(_In_z_ const char *str);
SWITCH_DECLARE(uint32_t) switch_log_str2mask(_In_z_ const char *str);
#define switch_log_check_mask(_mask, _level) (_mask & (1 << _level))
SWITCH_DECLARE(switch_log_node_t*) switch_log_node_dup(const switch_log_node_t *node);
SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode);
///\}
SWITCH_END_EXTERN_C
#endif

View File

@ -144,12 +144,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
switch_log_node_t *dnode = malloc(sizeof(*node));
switch_assert(dnode);
*dnode = *node;
dnode->data = strdup(node->data);
switch_assert(dnode->data);
switch_log_node_t *dnode = switch_log_node_dup(node);
if (switch_queue_trypush(l->log_queue, dnode) == SWITCH_STATUS_SUCCESS) {
if (l->lost_logs) {
@ -163,8 +158,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
}
}
} else {
switch_safe_free(dnode->data);
switch_safe_free(dnode);
switch_log_node_free(&dnode);
l->lost_logs++;
}
}
@ -182,8 +176,7 @@ static void flush_listener(listener_t *listener, switch_bool_t flush_log, switch
while (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_log_node_t *dnode = (switch_log_node_t *) pop;
if (dnode) {
free(dnode->data);
free(dnode);
switch_log_node_free(&dnode);
}
}
}
@ -889,8 +882,7 @@ SWITCH_STANDARD_API(event_sink_function)
encode_buf
);
free(encode_buf);
free(dnode->data);
free(dnode);
switch_log_node_free(&dnode);
}
stream->write_function(stream, "</log_data>\n");
@ -1168,10 +1160,9 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
switch_socket_send(listener->sock, buf, &len);
len = strlen(dnode->data);
switch_socket_send(listener->sock, dnode->data, &len);
free(dnode->data);
free(dnode);
}
switch_log_node_free(&dnode);
do_sleep = 0;
}
}

View File

@ -97,7 +97,26 @@ static switch_log_node_t* switch_log_node_alloc()
return node;
}
static void switch_log_node_free(switch_log_node_t **pnode)
SWITCH_DECLARE(switch_log_node_t*) switch_log_node_dup(const switch_log_node_t *node)
{
switch_log_node_t *newnode = switch_log_node_alloc();
*newnode = *node;
if (!switch_strlen_zero(node->data)) {
newnode->data = strdup(node->data);
switch_assert(node->data);
}
if (!switch_strlen_zero(node->userdata)) {
newnode->userdata = strdup(node->userdata);
switch_assert(node->userdata);
}
return newnode;
}
SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode)
{
switch_log_node_t *node;
@ -284,6 +303,7 @@ static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t *t, void *obj)
switch_mutex_unlock(BINDLOCK);
switch_log_node_free(&node);
}
THREAD_RUNNING = 0;