Fix memleaks
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 23 Dec 2011 19:02:30 +0000 (20:02 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Fri, 23 Dec 2011 19:02:30 +0000 (20:02 +0100)
  - properly cleanup pop3 client hashes
  - properly hook in the event cleanup stuff
  - move all cleanup into serv_eventclient.c

citadel/event_client.c
citadel/event_client.h
citadel/modules/eventclient/serv_eventclient.c
citadel/modules/pop3client/serv_pop3client.c

index b5e54b9593047411e3780e60411c49ed2ed14ed8..d87d6697f8bfc0ea79489cea15be4617bb87cd02 100644 (file)
@@ -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);
index ea68053d295bdd9cce9d9607f411824dfb344d6f..7210fcb41f7f95682b9b6bfe85c461ea5f6dccb4 100644 (file)
@@ -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, 
index 91e617617db8026c98b3da859827444317848634..53cbea4bd95e440734e2935fe84873ff8c438a3c 100644 (file)
@@ -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);
index f63b8afa573a953a25b277cb165d9ca82c6d6c23..efe1c8d8cc0a8934171e2e1bed33b6e8732fb42b 100644 (file)
@@ -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);
 }