From 42f8237ed1d90248818123340bc172c67b2f637c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Oct 2006 20:04:38 +0000 Subject: [PATCH] fix checks in new logger function. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3013 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 59bb8ad0fe..a15ba96cc8 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1686,25 +1686,27 @@ static const switch_loadable_module_interface_t sofia_module_interface = { static void logger(void *logarg, char const *fmt, va_list ap) { - char *data; - int ret; + char *data = NULL; if (fmt) { #ifdef HAVE_VASPRINTF + int ret; ret = vasprintf(&data, fmt, ap); -#else - data = (char *) malloc(2048); - vsnprintf(data, 2048, fmt, ap); -#endif - if (ret == -1) { + if ((ret == -1) || !data) { return; } +#else + data = (char *) malloc(2048); + if (data) { + vsnprintf(data, 2048, fmt, ap); + } else { + return; + } +#endif } - if (data) { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, (char*) "%s", data); - free(data); - } + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, (char*) "%s", data); + free(data); }