[dovecot-cvs] dovecot/src/lib strfuncs.c, 1.46, 1.47 strfuncs.h, 1.24, 1.25 imem.c, 1.10, 1.11

cras at dovecot.org cras at dovecot.org
Tue May 17 00:00:49 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv1892

Modified Files:
	strfuncs.c strfuncs.h imem.c 
Log Message:
If p_malloc() used data stack (with DEBUG enabled it might have written a
warning about growing memory pool), p_strconcat() gave corrupted reply. It
also didn't work correctly if the given pool was a data stack.

Also made i_strconcat() to be sure it doesn't break if default_pool's
p_malloc() for some reason would some day use data stack.



Index: strfuncs.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/strfuncs.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- strfuncs.c	7 Apr 2005 23:06:01 -0000	1.46
+++ strfuncs.c	16 May 2005 21:00:45 -0000	1.47
@@ -215,7 +215,7 @@
 	return ret;
 }
 
-const char *_vstrconcat(const char *str1, va_list args, size_t *ret_len)
+char *_vstrconcat(const char *str1, va_list args, size_t *ret_len)
 {
 	const char *str;
         char *temp;
@@ -254,20 +254,30 @@
 char *p_strconcat(pool_t pool, const char *str1, ...)
 {
 	va_list args;
-        const char *temp;
-	char *ret;
+	char *temp, *ret;
         size_t len;
 
 	va_start(args, str1);
 
+	if (!pool->datastack_pool)
+		t_push();
+
 	temp = _vstrconcat(str1, args, &len);
 	if (temp == NULL)
 		ret = NULL;
 	else {
-		ret = p_malloc(pool, len);
-		memcpy(ret, temp, len);
+		t_buffer_alloc(len);
+		if (pool->datastack_pool)
+			ret = temp;
+		else {
+			ret = p_malloc(pool, len);
+			memcpy(ret, temp, len);
+		}
 	}
 
+	if (!pool->datastack_pool)
+		t_pop();
+
 	va_end(args);
         return ret;
 }

Index: strfuncs.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/strfuncs.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- strfuncs.h	7 Jan 2005 18:09:41 -0000	1.24
+++ strfuncs.h	16 May 2005 21:00:45 -0000	1.25
@@ -71,6 +71,6 @@
 const char *t_strarray_join(const char *const *arr, const char *separator);
 
 /* INTERNAL */
-const char *_vstrconcat(const char *str1, va_list args, size_t *ret_len);
+char *_vstrconcat(const char *str1, va_list args, size_t *ret_len);
 
 #endif

Index: imem.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/imem.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- imem.c	21 Sep 2003 16:39:29 -0000	1.10
+++ imem.c	16 May 2005 21:00:45 -0000	1.11
@@ -59,13 +59,16 @@
 
 	va_start(args, str1);
 
+	t_push();
 	temp = _vstrconcat(str1, args, &len);
 	if (temp == NULL)
 		ret = NULL;
 	else {
+		t_buffer_alloc(len);
 		ret = p_malloc(default_pool, len);
 		memcpy(ret, temp, len);
 	}
+	t_pop();
 
 	va_end(args);
         return ret;



More information about the dovecot-cvs mailing list