From: Wilfried Goesgens Date: Fri, 23 Dec 2011 19:02:30 +0000 (+0100) Subject: Fix memleaks X-Git-Tag: v8.11~284 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=89e1a0f46082894132a09bd7e6401ee0ef1b013c Fix memleaks - properly cleanup pop3 client hashes - properly hook in the event cleanup stuff - move all cleanup into serv_eventclient.c --- diff --git a/citadel/event_client.c b/citadel/event_client.c index b5e54b959..d87d6697f 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -227,18 +227,6 @@ eNextState QueueCurlContext(AsyncIO *IO) return eSendReply; } -int ShutDownEventQueue(void) -{ - pthread_mutex_lock(&DBEventQueueMutex); - ev_async_send (event_db, &DBExitEventLoop); - pthread_mutex_unlock(&DBEventQueueMutex); - - pthread_mutex_lock(&EventQueueMutex); - ev_async_send (EV_DEFAULT_ &ExitEventLoop); - pthread_mutex_unlock(&EventQueueMutex); - return 0; -} - void FreeAsyncIOContents(AsyncIO *IO) { FreeStrBuf(&IO->IOBuf); diff --git a/citadel/event_client.h b/citadel/event_client.h index ea68053d2..7210fcb41 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -159,7 +159,6 @@ eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB); eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB); eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB); eNextState QueueCurlContext(AsyncIO *IO); -int ShutDownEventQueue(void); eNextState InitEventIO(AsyncIO *IO, void *pData, diff --git a/citadel/modules/eventclient/serv_eventclient.c b/citadel/modules/eventclient/serv_eventclient.c index 91e617617..53cbea4bd 100644 --- a/citadel/modules/eventclient/serv_eventclient.c +++ b/citadel/modules/eventclient/serv_eventclient.c @@ -458,7 +458,9 @@ static void WakeupCurlCallback(EV_P_ ev_async *w, int revents) static void evcurl_shutdown (void) { + curl_global_cleanup(); curl_multi_cleanup(global.mhnd); + syslog(LOG_DEBUG, "client_event_thread() initializing\n"); } /***************************************************************************** * libevent integration * @@ -551,7 +553,7 @@ void *client_event_thread(void *arg) CtdlFillSystemContext(&libev_client_CC, "LibEv Thread"); // citthread_setspecific(MyConKey, (void *)&smtp_queue_CC); - syslog(LOG_DEBUG, "client_ev_thread() initializing\n"); + syslog(LOG_DEBUG, "client_event_thread() initializing\n"); event_base = ev_default_loop (EVFLAG_AUTO); ev_async_init(&AddJob, QueueEventAddCallback); @@ -565,11 +567,10 @@ void *client_event_thread(void *arg) ev_run (event_base, 0); + syslog(LOG_DEBUG, "client_event_thread() exiting\n"); ///what todo here? CtdlClearSystemContext(); ev_loop_destroy (EV_DEFAULT_UC); - curl_global_cleanup(); - curl_multi_cleanup(global.mhnd); DeleteHash(&QueueEvents); InboundEventQueue = NULL; DeleteHash(&InboundEventQueues[0]); @@ -642,7 +643,7 @@ static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents) static void DBEventExitCallback(EV_P_ ev_async *w, int revents) { - syslog(LOG_DEBUG, "EVENT Q exiting.\n"); + syslog(LOG_DEBUG, "DB EVENT Q exiting.\n"); ev_break(event_db, EVBREAK_ALL); } @@ -679,7 +680,7 @@ void *db_event_thread(void *arg) CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread"); // citthread_setspecific(MyConKey, (void *)&smtp_queue_CC); - syslog(LOG_DEBUG, "client_msgev_thread() initializing\n"); + syslog(LOG_DEBUG, "dbevent_thread() initializing\n"); event_db = ev_loop_new (EVFLAG_AUTO); @@ -690,6 +691,7 @@ void *db_event_thread(void *arg) ev_run (event_db, 0); + syslog(LOG_DEBUG, "dbevent_thread() exiting\n"); //// what to do here? CtdlClearSystemContext(); ev_loop_destroy (event_db); @@ -703,10 +705,24 @@ void *db_event_thread(void *arg) return(NULL); } +void ShutDownEventQueues(void) +{ + syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n"); + + pthread_mutex_lock(&DBEventQueueMutex); + ev_async_send (event_db, &DBExitEventLoop); + pthread_mutex_unlock(&DBEventQueueMutex); + + pthread_mutex_lock(&EventQueueMutex); + ev_async_send (EV_DEFAULT_ &ExitEventLoop); + pthread_mutex_unlock(&EventQueueMutex); +} + CTDL_MODULE_INIT(event_client) { if (!threading) { + CtdlRegisterCleanupHook(ShutDownEventQueues); InitEventQueue(); DBInitEventQueue(); CtdlThreadCreate(/*"Client event", */ client_event_thread); diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index f63b8afa5..efe1c8d8c 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -1049,10 +1049,10 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data) FreeStrBuf(&CfgData); } +static int doing_pop3client = 0; void pop3client_scan(void) { static time_t last_run = 0L; - static int doing_pop3client = 0; /// struct pop3aggr *pptr; time_t fastest_scan; HashPos *it; @@ -1117,7 +1117,8 @@ void pop3client_scan(void) { void pop3_cleanup(void) { /* citthread_mutex_destroy(&POP3QueueMutex); TODO */ -// DeleteHash(&POP3FetchUrls); + while (doing_pop3client != 0) ; + DeleteHash(&POP3FetchUrls); DeleteHash(&POP3QueueRooms); }