[Freeswitch-svn] [commit] r8505 - freeswitch/trunk/src/mod/endpoints/mod_woomera

Freeswitch SVN stkn at freeswitch.org
Wed May 21 15:54:24 EDT 2008


Author: stkn
Date: Wed May 21 15:54:23 2008
New Revision: 8505

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c

Log:
Make woomera_printf() a little more robust (Klocwork #530 related)

Modified: freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c	Wed May 21 15:54:23 2008
@@ -471,7 +471,7 @@
 
 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 @@
 #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 @@
 		}
 		len = strlen(stuff);
 		switch_socket_send(socket, stuff, &len);
+	}
 
+	if (stuff) {
 		free(stuff);
 	}
-
 }
 
 static char *woomera_message_header(woomera_message * wmsg, char *key)



More information about the Freeswitch-svn mailing list