changeset 173:83fe0be032c1 stable-6-0-9

fix leak, update timestamps when receiving auto-whitelisted sender
author carl
date Thu, 06 Sep 2007 09:50:05 -0700
parents d3189495ec68
children da0c41b9f672
files ChangeLog NEWS configure.in src/context.cpp src/context.h src/dnsbl.cpp
diffstat 6 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Aug 30 18:50:00 2007 -0700
+++ b/ChangeLog	Thu Sep 06 09:50:05 2007 -0700
@@ -1,5 +1,9 @@
     $Id$
 
+6.09 2007-09-06
+    Fix memory leak in auto-whitelisting code. Update auto-whitelist
+    timestamps when receiving mail from auto-whitelisted senders.
+
 6.08 2007-08-30
     Don't do generic reverse dns filtering on authenticated connections.
 
--- a/NEWS	Thu Aug 30 18:50:00 2007 -0700
+++ b/NEWS	Thu Sep 06 09:50:05 2007 -0700
@@ -1,5 +1,6 @@
     $Id$
 
+6.09 2007-09-06 Fix memory leak. Update timestamps when receiving from auto-whitelisted sender.
 6.08 2007-08-30 Don't do generic reverse dns filtering on authenticated connections.
 6.07 2007-08-30 Add generic reverse dns filtering with regular expression.
 6.06 2007-08-27 Fix bug that effectively disabled spamassassin filtering.
--- a/configure.in	Thu Aug 30 18:50:00 2007 -0700
+++ b/configure.in	Thu Sep 06 09:50:05 2007 -0700
@@ -1,6 +1,6 @@
 
 AC_PREREQ(2.59)
-AC_INIT(dnsbl,6.08,carl@five-ten-sg.com)
+AC_INIT(dnsbl,6.09,carl@five-ten-sg.com)
 AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADER([config.h])
 
--- a/src/context.cpp	Thu Aug 30 18:50:00 2007 -0700
+++ b/src/context.cpp	Thu Sep 06 09:50:05 2007 -0700
@@ -69,7 +69,7 @@
 pthread_mutex_t verifier_mutex; 	// protect the verifier map
 verify_map	verifiers;
 
-pthread_mutex_t whitelister_mutex;	// protect the
+pthread_mutex_t whitelister_mutex;	// protect the whitelisters map
 whitelister_map whitelisters;
 
 string_set	all_strings;	// owns all the strings, only modified by the config loader thread
@@ -447,12 +447,13 @@
 				time_t when = atoi(p+1);
 				if ((when == 0) || (when > now)) when = now;
 				autowhite_sent::iterator i = rcpts.find(who);
-				if (i != rcpts.end()) {
-					time_t wh = (*i).second;
-					if (when > wh) rcpts[who] = when;
+				if (i == rcpts.end()) {
+					rcpts[who] = when;
 				}
 				else {
-					rcpts[who] = when;
+					time_t wh = (*i).second;
+					if (when > wh) (*i).second = when;
+					free(who);
 				}
 			}
 		}
@@ -512,7 +513,14 @@
 	// we take ownership of the string
 	pthread_mutex_lock(&mutex);
 		need = true;
+		autowhite_sent::iterator i = rcpts.find(to);
+		if (i == rcpts.end()) {
 		rcpts[to] = time(NULL);
+		}
+		else {
+			(*i).second = time(NULL);
+			free(to);
+		}
 	pthread_mutex_unlock(&mutex);
 }
 
@@ -784,8 +792,20 @@
 }
 
 
-char *CONTEXT::find_from(char *from) {
-	if (whitelister && whitelister->is_white(from)) return token_white;
+char *CONTEXT::find_from(char *from, bool update_white) {
+	if (whitelister && whitelister->is_white(from)) {
+		if (update_white) {
+			// update senders timestamp to extend the whitelisting period
+			if (debug_syslog > 1) {
+				char buf[maxlen];
+				char msg[maxlen];
+				snprintf(msg, sizeof(msg), "extend whitelist reply from <%s> in context %s", from, get_full_name(buf,maxlen));
+				my_syslog(msg);
+			}
+			whitelister->sent(strdup(from));
+		}
+		return token_white;
+	}
 	char *rc = env_from_default;
 	string_map::iterator i = env_from.find(from);
 	if (i != env_from.end()) rc = (*i).second;	// found user@domain key
--- a/src/context.h	Thu Aug 30 18:50:00 2007 -0700
+++ b/src/context.h	Thu Sep 06 09:50:05 2007 -0700
@@ -182,7 +182,7 @@
 	void		add_from(char *from, char *status)			{env_from[from] = status;};
 	void		add_from_context(char *from, CONTEXTP con)	{env_from_context[from] = con;};
 	void		set_from_default(char *status)				{env_from_default = status;};
-	char*		find_from(char *from);
+	char*		find_from(char *from, bool update_white = false);
 	CONTEXTP	find_context(char *from);
 	CONTEXTP	find_from_context_name(char *name);
 
--- a/src/dnsbl.cpp	Thu Aug 30 18:50:00 2007 -0700
+++ b/src/dnsbl.cpp	Thu Sep 06 09:50:05 2007 -0700
@@ -988,7 +988,7 @@
 	// priv.mailaddr sending original message to loto
 	CONTEXT 	&con = *(dc.find_context(loto)->find_context(priv.mailaddr));
 	VERIFYP 	 ver = con.find_verify(loto);
-	char  *fromvalue = con.find_from(priv.mailaddr);
+	char  *fromvalue = con.find_from(priv.mailaddr, true);
 	// loto sending a reply back to priv.mailaddr
 	CONTEXT    &con2 = *(dc.find_context(priv.mailaddr)->find_context(loto));
 	char *replyvalue = con2.find_from(loto);