From fa2530306f5d9d98eb79d75a4d73a30dd250ab57 Mon Sep 17 00:00:00 2001 From: Nathan Neulinger Date: Fri, 2 Aug 2013 21:25:51 -0500 Subject: [PATCH] mod_skinny work on FS-5632 - few more cases --- src/mod/endpoints/mod_skinny/mod_skinny.c | 4 +++- src/mod/endpoints/mod_skinny/skinny_protocol.c | 10 +++++++++- src/mod/endpoints/mod_skinny/skinny_server.c | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_skinny/mod_skinny.c b/src/mod/endpoints/mod_skinny/mod_skinny.c index ab4398a898..13a94810f8 100644 --- a/src/mod/endpoints/mod_skinny/mod_skinny.c +++ b/src/mod/endpoints/mod_skinny/mod_skinny.c @@ -1604,9 +1604,11 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj) if (skinny_handle_request(listener, request) != SWITCH_STATUS_SUCCESS) { switch_clear_flag_locked(listener, LFLAG_RUNNING); + switch_safe_free(request); break; + } else { + switch_safe_free(request); } - } remove_listener(listener); diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.c b/src/mod/endpoints/mod_skinny/skinny_protocol.c index 2de3b87e27..ce756da34a 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.c +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.c @@ -110,7 +110,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) char *ptr; switch_status_t status = SWITCH_STATUS_SUCCESS; - request = switch_core_alloc(listener->pool, SKINNY_MESSAGE_MAXSIZE); + request = calloc(SKINNY_MESSAGE_MAXSIZE,1); if (!request) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate memory.\n"); @@ -122,6 +122,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) while (listener_is_ready(listener)) { uint8_t do_sleep = 1; if (listener->expire_time && listener->expire_time < switch_epoch_time_now(NULL)) { + switch_safe_free(request); return SWITCH_STATUS_TIMEOUT; } if(bytes < SKINNY_MESSAGE_FIELD_SIZE) { @@ -135,6 +136,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) status = switch_socket_recv(listener->sock, ptr, &mlen); if (listener->expire_time && listener->expire_time < switch_epoch_time_now(NULL)) { + switch_safe_free(request); return SWITCH_STATUS_TIMEOUT; } @@ -143,6 +145,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) } if (!switch_status_is_timeup(status) && !SWITCH_STATUS_IS_BREAK(status) && (status != SWITCH_STATUS_SUCCESS)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break with status=%d.\n", status); + switch_safe_free(request); return SWITCH_STATUS_FALSE; } @@ -162,17 +165,20 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Skinny client sent invalid data. Length should be greater than 4 but got %d.\n", request->length); + switch_safe_free(request); return SWITCH_STATUS_FALSE; } if(request->length + 2*SKINNY_MESSAGE_FIELD_SIZE > SKINNY_MESSAGE_MAXSIZE) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Skinny client sent too huge data. Got %d which is above threshold %d.\n", request->length, SKINNY_MESSAGE_MAXSIZE - 2*SKINNY_MESSAGE_FIELD_SIZE); + switch_safe_free(request); return SWITCH_STATUS_FALSE; } if(bytes >= request->length + 2*SKINNY_MESSAGE_FIELD_SIZE) { /* Message body */ *req = request; + /* Do not free here, caller needs to do it */ return SWITCH_STATUS_SUCCESS; } } @@ -181,6 +187,8 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) switch_cond_next(); } } + + switch_safe_free(request); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c index 193b26a36f..dff09844e7 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.c +++ b/src/mod/endpoints/mod_skinny/skinny_server.c @@ -1687,7 +1687,11 @@ switch_status_t skinny_handle_capabilities_response(listener_t *listener, skinny } i = 0; pos = 0; - codec_string = switch_core_alloc(listener->pool, string_len+1); + codec_string = calloc(string_len+1,1); + if ( !codec_string ) { + skinny_log_l_msg(listener, SWITCH_LOG_ERROR, "Unable to allocate memory for codec string.\n"); + return SWITCH_STATUS_FALSE; + } for (string_pos = 0; string_pos < string_len; string_pos++) { char *codec = codec_order[i]; switch_assert(i < n); @@ -1709,6 +1713,7 @@ switch_status_t skinny_handle_capabilities_response(listener_t *listener, skinny switch_safe_free(sql); } skinny_log_l(listener, SWITCH_LOG_DEBUG, "Codecs %s supported.\n", codec_string); + switch_safe_free(codec_string); return SWITCH_STATUS_SUCCESS; }