[Dbmail-dev] Possible minor memleaks in svn trunk 2474

2007-03-23 Thread Leif Jackson

Paul  Aaron,

I was reviewing the current trunk 2474 from today, to see if I can help 
make 2.2.5 bug free :) Anyway I came across some possible memleak issues 
patch is attached. This is from valgrind I deduced the issues. Please 
verify and apply to the trunk if you see fit.


Thanks,
Leif Jackson
diff -urN dbmail-svn-2.2.4-2474.orig/dbmail-message.c dbmail-svn-2.2.4-2474.new/dbmail-message.c
--- dbmail-svn-2.2.4-2474.orig/dbmail-message.c	2007-03-23 14:09:34.0 -0400
+++ dbmail-svn-2.2.4-2474.new/dbmail-message.c	2007-03-23 14:49:59.0 -0400
@@ -1109,6 +1109,7 @@
 	g_string_printf(q, INSERT INTO %s%sfield (id, physmessage_id, %sfield) 
 			VALUES (%s, %llu,'%s'), DBPFX, field, field, id, physid, clean_value);
 	g_free(id);
+	g_free(sid);
 	g_free(clean_value);
 
 	if (db_query(q-str)) {
diff -urN dbmail-svn-2.2.4-2474.orig/imapd.c dbmail-svn-2.2.4-2474.new/imapd.c
--- dbmail-svn-2.2.4-2474.orig/imapd.c	2007-03-23 14:09:34.0 -0400
+++ dbmail-svn-2.2.4-2474.new/imapd.c	2007-03-23 16:59:46.0 -0400
@@ -40,6 +40,10 @@
 	g_mime_init(0);
 	openlog(PNAME, LOG_PID, LOG_MAIL);
 
+	//fixes valgrind Conditional jump or move depends on uninitialised value(s)
+	config.iplist = NULL;
+	config.listenSockets = NULL;
+
 	result = serverparent_getopt(config, IMAP, argc, argv);
 	if (result == -1)
 		goto shutdown;
diff -urN dbmail-svn-2.2.4-2474.orig/lmtpd.c dbmail-svn-2.2.4-2474.new/lmtpd.c
--- dbmail-svn-2.2.4-2474.orig/lmtpd.c	2007-03-23 14:09:33.0 -0400
+++ dbmail-svn-2.2.4-2474.new/lmtpd.c	2007-03-23 16:59:41.0 -0400
@@ -40,6 +40,10 @@
 	g_mime_init(0);
 	openlog(PNAME, LOG_PID, LOG_MAIL);
 
+	//fixes valgrind Conditional jump or move depends on uninitialised value(s)
+config.iplist = NULL;
+config.listenSockets = NULL;
+
 	result = serverparent_getopt(config, LMTP, argc, argv);
 	if (result == -1)
 		goto shutdown;
diff -urN dbmail-svn-2.2.4-2474.orig/misc.c dbmail-svn-2.2.4-2474.new/misc.c
--- dbmail-svn-2.2.4-2474.orig/misc.c	2007-03-23 14:09:34.0 -0400
+++ dbmail-svn-2.2.4-2474.new/misc.c	2007-03-23 16:58:04.0 -0400
@@ -2015,6 +2015,7 @@
 	}
 	if (subj==NULL) {
 		subj=g_mime_iconv_strdup(default_iconv,str_in);
+		g_mime_iconv_close(default_iconv);
 	}
 	
 	if (subj==NULL) {
@@ -2036,6 +2037,7 @@
 	//char * str_out=NULL;
 	char * subj=NULL;
 	//int err_flg=1;
+	int allocated_default_iconv = 0;
 	static const char * base_charset=NULL;
 	static iconv_t base_iconv=(iconv_t)-1;
 	static iconv_t default_iconv=(iconv_t)-1;
@@ -2075,17 +2077,22 @@
 		if (default_iconv == (iconv_t)-1) {
 			TRACE(TRACE_DEBUG,incorrect default encoding [%s], default_charset);
 		}
+		allocated_default_iconv = 1;
 	}
-	if (str_in==NULL)
+	if (str_in==NULL) {
+		if(allocated_default_iconv) g_mime_iconv_close(default_iconv);
 		return NULL;
+	}
 	
 	if (!g_mime_utils_text_is_8bit((unsigned char *)str_in, strlen(str_in))) {
 		// Conversion not needed
+		if(allocated_default_iconv) g_mime_iconv_close(default_iconv);
 		return g_strdup(str_in);
 	}
 
 	if ((subj=g_mime_iconv_strdup(base_iconv,str_in))!=NULL) {
 		// Conversion already done by header decode ? May insert to database
+		if(allocated_default_iconv) g_mime_iconv_close(default_iconv);
 		return subj;
 	}
 	
@@ -2117,6 +2124,9 @@
 		if(*p  0x80) *p='?';
 	}
 
+	if(allocated_default_iconv)
+		g_mime_iconv_close(default_iconv);
+
 	return subj;
 }
 
diff -urN dbmail-svn-2.2.4-2474.orig/pop3d.c dbmail-svn-2.2.4-2474.new/pop3d.c
--- dbmail-svn-2.2.4-2474.orig/pop3d.c	2007-03-23 14:09:34.0 -0400
+++ dbmail-svn-2.2.4-2474.new/pop3d.c	2007-03-23 17:00:07.0 -0400
@@ -44,6 +44,10 @@
 	g_mime_init(0);
 	openlog(PNAME, LOG_PID, LOG_MAIL);
 
+//fixes valgrind Conditional jump or move depends on uninitialised value(s)
+config.iplist = NULL;
+config.listenSockets = NULL;
+
 	result = serverparent_getopt(config, POP, argc, argv);
 	if (result == -1)
 		goto shutdown;
diff -urN dbmail-svn-2.2.4-2474.orig/serverparent.c dbmail-svn-2.2.4-2474.new/serverparent.c
--- dbmail-svn-2.2.4-2474.orig/serverparent.c	2007-03-23 14:09:34.0 -0400
+++ dbmail-svn-2.2.4-2474.new/serverparent.c	2007-03-23 16:04:22.0 -0400
@@ -167,6 +167,7 @@
 		 * e.g. on SIGHUP or other graceful restart condition. */
 		DoConfig(config, service); }
 
+	ClearConfig(config);
 	TRACE(TRACE_INFO, leaving main loop);
 	return 0;
 }
diff -urN dbmail-svn-2.2.4-2474.orig/timsieved.c dbmail-svn-2.2.4-2474.new/timsieved.c
--- dbmail-svn-2.2.4-2474.orig/timsieved.c	2007-03-23 14:09:33.0 -0400
+++ dbmail-svn-2.2.4-2474.new/timsieved.c	2007-03-23 17:00:26.0 -0400
@@ -42,6 +42,10 @@
 	g_mime_init(0);
 	openlog(PNAME, LOG_PID, LOG_MAIL);
 
+//fixes valgrind Conditional jump or move depends on uninitialised value(s)
+config.iplist = NULL;
+config.listenSockets = NULL;
+
 	result = serverparent_getopt(config, SIEVE, argc, argv);
 	if (result == -1)
 		goto shutdown;

Re: [Dbmail-dev] Possible minor memleaks in svn trunk 2474

2007-03-23 Thread Aaron Stone
Nice work, now in SVN, except for the changes to dbmail-message.c which
Paul appears to have already incorportated into renamed variables.

Aaron

On Fri, 2007-03-23 at 17:12 -0500, Leif Jackson wrote:
 Paul  Aaron,
 
  I was reviewing the current trunk 2474 from today, to see if I can help 
 make 2.2.5 bug free :) Anyway I came across some possible memleak issues 
 patch is attached. This is from valgrind I deduced the issues. Please 
 verify and apply to the trunk if you see fit.
 
 Thanks,
 Leif Jackson
 ___
 Dbmail-dev mailing list
 Dbmail-dev@dbmail.org
 http://twister.fastxs.net/mailman/listinfo/dbmail-dev

___
Dbmail-dev mailing list
Dbmail-dev@dbmail.org
http://twister.fastxs.net/mailman/listinfo/dbmail-dev