From 3f6b5a5c013f6f80544c5b35ec5032c53cad5738 Mon Sep 17 00:00:00 2001 From: Tamas Cseke Date: Mon, 11 Jun 2012 17:25:28 +0200 Subject: [PATCH] fix reply timeout: move hash and pid to session pool FS-3432 --- .../mod_erlang_event/handle_msg.c | 18 +++++------------- .../mod_erlang_event/mod_erlang_event.c | 4 +--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/mod/event_handlers/mod_erlang_event/handle_msg.c b/src/mod/event_handlers/mod_erlang_event/handle_msg.c index 527828f1f7..0e8d472585 100644 --- a/src/mod/event_handlers/mod_erlang_event/handle_msg.c +++ b/src/mod/event_handlers/mod_erlang_event/handle_msg.c @@ -1108,7 +1108,7 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf) { erlang_ref ref; - erlang_pid *pid; + erlang_pid pid; char hash[100]; int arity; const void *key; @@ -1123,15 +1123,7 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, return SWITCH_STATUS_FALSE; } - if (!(pid = malloc(sizeof(erlang_pid)))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n"); - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_atom(rbuf, "badmem"); - return SWITCH_STATUS_SUCCESS; - } - - if (ei_decode_pid(buf->buff, &buf->index, pid)) { + if (ei_decode_pid(buf->buff, &buf->index, &pid)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid pid in a reference/pid tuple\n"); return SWITCH_STATUS_FALSE; } @@ -1149,7 +1141,9 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, switch_mutex_lock(se->spawn_reply->mutex); if (se->spawn_reply->state == reply_waiting) { - se->spawn_reply->pid = pid; + se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid)); + switch_assert(se->spawn_reply->pid != NULL); + memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid)); switch_thread_cond_signal(se->spawn_reply->ready_or_found); ei_x_encode_atom(rbuf, "ok"); switch_thread_rwlock_unlock(listener->session_rwlock); @@ -1167,8 +1161,6 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "notfound"); - switch_safe_free(pid); /* don't need it */ - return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index 9960e2499d..4b3eaa7ecd 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1377,7 +1377,7 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul switch_thread_cond_create(&p->ready_or_found, session_element->pool); switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, session_element->pool); p->state = reply_waiting; - p->hash = hash; + p->hash = switch_core_strdup(session_element->pool, hash); p->pid = NULL; session_element->spawn_reply = p; @@ -1437,8 +1437,6 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul ei_link(listener, ei_self(listener->ec), &session_element->process.pid); - switch_safe_free(p->pid); - return session_element; }