From 6820f1a4cf617af0c6ec942587f9de12a1a54a49 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 21 May 2008 19:54:23 +0000 Subject: [PATCH] Make woomera_printf() a little more robust (Klocwork #530 related) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8505 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_woomera/mod_woomera.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_woomera/mod_woomera.c b/src/mod/endpoints/mod_woomera/mod_woomera.c index da9eeb3ad6..fbec74a1d3 100644 --- a/src/mod/endpoints/mod_woomera/mod_woomera.c +++ b/src/mod/endpoints/mod_woomera/mod_woomera.c @@ -471,7 +471,7 @@ static void tech_destroy(private_object * tech_pvt) static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, char *fmt, ...) { - char *stuff; + char *stuff = NULL; size_t res = 0, len = 0; va_list ap; @@ -479,13 +479,13 @@ static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, #ifndef vasprintf stuff = (char *) malloc(10240); switch_assert(stuff); - vsnprintf(stuff, 10240, fmt, ap); + res = vsnprintf(stuff, 10240, fmt, ap); #else res = vasprintf(&stuff, fmt, ap); switch_assert(stuff); #endif va_end(ap); - if (res == -1) { + if (res < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Out of memory\n"); } else { if (profile && globals.debug) { @@ -494,10 +494,11 @@ static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, } len = strlen(stuff); switch_socket_send(socket, stuff, &len); - - free(stuff); } + if (stuff) { + free(stuff); + } } static char *woomera_message_header(woomera_message * wmsg, char *key)