Mercurial > dnsbl
diff src/dnsbl.cpp @ 12:6ac6d6b822ce stable-2-0
fix memory leak with duplicate url host names,
document differences from sendmail.mc feature
author | carl |
---|---|
date | Fri, 23 Apr 2004 22:45:10 -0700 |
parents | 2c206836b4cc |
children | 2752e512fd32 |
line wrap: on
line diff
--- a/src/dnsbl.cpp Thu Apr 22 20:19:01 2004 -0700 +++ b/src/dnsbl.cpp Fri Apr 23 22:45:10 2004 -0700 @@ -146,11 +146,6 @@ static pthread_mutex_t resolve_mutex; - -// include the content scanner -#include "scanner.cpp" - - //////////////////////////////////////////////// // helper to discard the strings held by a string_set // @@ -162,6 +157,22 @@ s.clear(); } +//////////////////////////////////////////////// +// helper to register a string in a string set +// +static char* register_string(string_set &s, char *name); +static char* register_string(string_set &s, char *name) { + string_set::iterator i = s.find(name); + if (i != s.end()) return *i; + char *x = strdup(name); + s.insert(x); + return x; +} + +// include the content scanner +#include "scanner.cpp" + + //////////////////////////////////////////////// // mail filter private data, held for us by sendmail @@ -179,7 +190,7 @@ bool only_whites; // every recipient is whitelisted? url_scanner *scanner; // object to handle body scanning string_set non_whites; // remember the non-whitelisted recipients so we can remove them if need be - string_set urls; // remember the urls that we have checked + string_set hosts; // remember the hosts that we have checked mlfiPriv(); ~mlfiPriv(); void reset(bool final = false); // for a new message @@ -194,7 +205,7 @@ authenticated = false; have_whites = false; only_whites = true; - scanner = new url_scanner(&urls); + scanner = new url_scanner(&hosts); } mlfiPriv::~mlfiPriv() { pthread_mutex_lock(&config_mutex); @@ -206,13 +217,13 @@ if (mailaddr) free(mailaddr); delete scanner; discard(non_whites); - discard(urls); + discard(hosts); if (!final) { mailaddr = NULL; authenticated = false; have_whites = false; only_whites = true; - scanner = new url_scanner(&urls); + scanner = new url_scanner(&hosts); } } @@ -237,11 +248,7 @@ // static char* register_string(char *name); static char* register_string(char *name) { - string_set::iterator i = all_strings.find(name); - if (i != all_strings.end()) return *i; - char *x = strdup(name); - all_strings.insert(x); - return x; + return register_string(all_strings, name); } @@ -425,14 +432,14 @@ //////////////////////////////////////////////// // check the dnsbls specified for this recipient // -static status check_urls(mlfiPriv &priv, char *&url, int &ip); -static status check_urls(mlfiPriv &priv, char *&url, int &ip) { +static status check_hosts(mlfiPriv &priv, char *&url, int &ip); +static status check_hosts(mlfiPriv &priv, char *&url, int &ip) { CONFIG &dc = *priv.pc; if (!dc.content_suffix) return oksofar; int count = 0; - for (string_set::iterator i=priv.urls.begin(); i!=priv.urls.end(); i++) { + for (string_set::iterator i=priv.hosts.begin(); i!=priv.hosts.end(); i++) { count++; - if (count > 20) return oksofar; // silly to check too many urls + if (count > 20) return oksofar; // silly to check too many hosts url = *i; char buf[200]; snprintf(buf, sizeof(buf), "looking for url %s", url); @@ -526,7 +533,7 @@ // accept the recipient if (st == oksofar) { // but remember the non-whites - priv.non_whites.insert(strdup(rcptaddr)); + register_string(priv.non_whites, rcptaddr); priv.only_whites = false; } if (st == white) { @@ -554,7 +561,7 @@ // process end of message if (priv.authenticated || priv.only_whites || - (check_urls(priv, url, ip) == oksofar)) rc = SMFIS_CONTINUE; + (check_hosts(priv, url, ip) == oksofar)) rc = SMFIS_CONTINUE; else { if (!priv.have_whites) { // can reject the entire message