[Freeswitch-svn] [commit] r4756 - freeswitch/trunk/src

Freeswitch SVN mikej at freeswitch.org
Fri Mar 23 18:44:28 EDT 2007


Author: mikej
Date: Fri Mar 23 18:44:28 2007
New Revision: 4756

Modified:
   freeswitch/trunk/src/switch_apr.c
   freeswitch/trunk/src/switch_console.c

Log:
a little realloc never hurt anyone.

Modified: freeswitch/trunk/src/switch_apr.c
==============================================================================
--- freeswitch/trunk/src/switch_apr.c	(original)
+++ freeswitch/trunk/src/switch_apr.c	Fri Mar 23 18:44:28 2007
@@ -657,8 +657,31 @@
 #ifdef HAVE_VASPRINTF
     return vasprintf(buf, format, ap);
 #else
-    *buf = (char *) malloc(2048);
-    return vsnprintf(*buf, 2048, format, ap);
+	size_t block_size = 1024;
+	int ret = -1;
+	int count = 1;
+	*buf = (char *) malloc(block_size);
+
+	if (*buf == NULL) {
+        return -1;
+    }
+	
+	while (ret == -1 && count < 10) {
+		ret = vsnprintf(*buf, block_size*count, format, ap);
+		if (ret == -1) {
+			void *new_buf;
+			count++;
+			new_buf = realloc(*buf, block_size*count);
+			if (new_buf == NULL) {
+				*buf = NULL;
+				return -1;
+			} else {
+				*buf = new_buf;
+			}
+		}
+	}
+	return ret;
+
 #endif
 }
 

Modified: freeswitch/trunk/src/switch_console.c
==============================================================================
--- freeswitch/trunk/src/switch_console.c	(original)
+++ freeswitch/trunk/src/switch_console.c	Fri Mar 23 18:44:28 2007
@@ -41,7 +41,7 @@
 	char *buf = handle->data;
 	char *end = handle->end;
 	int ret = 0;
-	char *data;
+	char *data = NULL;
 
 	if (handle->data_len >= handle->data_size) {
 		return SWITCH_STATUS_FALSE;



More information about the Freeswitch-svn mailing list