# HG changeset patch # User carl # Date 1160958067 25200 # Node ID 7278c9766e269627f8d419f135386f03af9d9123 # Parent 9b9bab1d3c21bfe9d4baa3aa534be74f594fa04b free old configs when last reference goes away diff -r 9b9bab1d3c21 -r 7278c9766e26 src/context.cpp --- a/src/context.cpp Sun Oct 15 12:41:46 2006 -0700 +++ b/src/context.cpp Sun Oct 15 17:21:07 2006 -0700 @@ -395,6 +395,11 @@ CONFIG::~CONFIG() { + if (debug_syslog) { + char buf[maxlen]; + snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", generation); + my_syslog(buf); + } for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { CONTEXT *c = *i; delete c; diff -r 9b9bab1d3c21 -r 7278c9766e26 src/dnsbl.cpp --- a/src/dnsbl.cpp Sun Oct 15 12:41:46 2006 -0700 +++ b/src/dnsbl.cpp Sun Oct 15 17:21:07 2006 -0700 @@ -261,7 +261,9 @@ return_fd(); pthread_mutex_lock(&config_mutex); pc->reference_count--; + bool last = (!pc->reference_count) && (pc != config); pthread_mutex_unlock(&config_mutex); + if (last) delete pc; // free this config, since we were the last reference to it reset(true); } @@ -1160,15 +1162,13 @@ //////////////////////////////////////////////// // thread to watch the old config files for changes -// and reload when needed. we also cleanup old -// configs whose reference count has gone to zero. +// and reload when needed. // we also clear the SMTP AUTH recipient counts hourly // void* config_loader(void *arg); void* config_loader(void *arg) { int loop = 0; typedef set configp_set; - configp_set old_configs; while (loader_run) { sleep(180); // look for modifications every 3 minutes if (!loader_run) break; @@ -1198,10 +1198,11 @@ if (newc) { // replace the global config pointer pthread_mutex_lock(&config_mutex); - CONFIG *old = config; + CONFIG *pc = config; + bool last = pc && (!pc->reference_count); config = newc; pthread_mutex_unlock(&config_mutex); - if (old) old_configs.insert(old); + if (last) delete pc; // there were no references to this config } else { // failed to load new config @@ -1211,20 +1212,6 @@ dc.load_time = time(NULL); } } - // now look for old configs with zero ref counts - for (configp_set::iterator i=old_configs.begin(); i!=old_configs.end(); ) { - CONFIG *old = *i; - if (!old->reference_count) { - if (debug_syslog) { - char buf[maxlen]; - snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", old->generation); - my_syslog(buf); - } - delete old; // destructor does all the work - old_configs.erase(i++); - } - else i++; - } } return NULL; }