]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_skinny work on FS-5632 - few more cases
authorNathan Neulinger <nneul@neulinger.org>
Sat, 3 Aug 2013 02:25:51 +0000 (21:25 -0500)
committerNathan Neulinger <nneul@neulinger.org>
Sat, 3 Aug 2013 02:25:51 +0000 (21:25 -0500)
src/mod/endpoints/mod_skinny/mod_skinny.c
src/mod/endpoints/mod_skinny/skinny_protocol.c
src/mod/endpoints/mod_skinny/skinny_server.c

index ab4398a8986e40dbaf356824185e1828d97a36cb..13a94810f89a39a18704e41785c2e4f37e2469bb 100644 (file)
@@ -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);
index 2de3b87e27eb5c2ac33a3c7f71473b42f40a399b..ce756da34a58fe08c9d13aedba0e415ef75753fb 100644 (file)
@@ -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;
 }
 
index 36e3f07d045238f22f12de7976a9631650600f1d..f3dda49f1bfc3abfe7434fe6d1b905103adde48c 100644 (file)
@@ -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;
 }