]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/pop3client/serv_pop3client.c
free the context on that exit place too.
[citadel.git] / citadel / modules / pop3client / serv_pop3client.c
index 775a892ce3c19c46f3eed38c5c57484164d0403e..34bb969c9c7e21b4e7c03f3813e4f3ab2c3b186d 100644 (file)
@@ -82,6 +82,7 @@ void pop3_do_fetching(char *roomname, char *pop3host, char *pop3user, char *pop3
        char utmsgid[SIZ];
        struct cdbdata *cdbut;
        struct UseTable ut;
+       CitContext *CCC=CC;
 
        CtdlLogPrintf(CTDL_DEBUG, "POP3: %s %s %s <password>\n", roomname, pop3host, pop3user);
        CtdlLogPrintf(CTDL_NOTICE, "Connecting to <%s>\n", pop3host);
@@ -99,6 +100,9 @@ void pop3_do_fetching(char *roomname, char *pop3host, char *pop3user, char *pop3
                goto bail;
 
        CtdlLogPrintf(CTDL_DEBUG, "Connected!\n");
+       CCC->sReadBuf = NewStrBuf();
+       CCC->sMigrateBuf = NewStrBuf();
+       CCC->sPos = NULL;
 
        /* Read the server greeting */
        if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
@@ -243,6 +247,9 @@ void pop3_do_fetching(char *roomname, char *pop3host, char *pop3user, char *pop3
        if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
        CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
 bail:  
+       FreeStrBuf(&CCC->sReadBuf);
+       FreeStrBuf(&CCC->sMigrateBuf);
+
        if (sock != -1)
                sock_close(sock);
        if (msglist) free(msglist);
@@ -301,7 +308,12 @@ void pop3client_scan(void) {
        static int doing_pop3client = 0;
        struct pop3aggr *pptr;
        time_t fastest_scan;
-       
+       CitContext popclientCC;
+
+       /* Give this thread its own private CitContext */
+       CtdlFillSystemContext(&popclientCC, "popclient");
+       citthread_setspecific(MyConKey, (void *)&popclientCC );
+
        if (config.c_pop3_fastest < config.c_pop3_fetch)
                fastest_scan = config.c_pop3_fastest;
        else
@@ -311,6 +323,7 @@ void pop3client_scan(void) {
         * Run POP3 aggregation no more frequently than once every n seconds
         */
        if ( (time(NULL) - last_run) < fastest_scan ) {
+               CtdlClearSystemContext();
                return;
        }
 
@@ -320,7 +333,10 @@ void pop3client_scan(void) {
         * don't really require extremely fine granularity here, we'll do it
         * with a static variable instead.
         */
-       if (doing_pop3client) return;
+       if (doing_pop3client) {
+               CtdlClearSystemContext();
+               return;
+       }
        doing_pop3client = 1;
 
        CtdlLogPrintf(CTDL_DEBUG, "pop3client started\n");
@@ -339,6 +355,7 @@ void pop3client_scan(void) {
        CtdlLogPrintf(CTDL_DEBUG, "pop3client ended\n");
        last_run = time(NULL);
        doing_pop3client = 0;
+       CtdlClearSystemContext();
 }