libev migration - copy valus we use for loop control before we hand it off into the...
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 30 Jan 2011 20:28:35 +0000 (21:28 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 30 Jan 2011 20:28:35 +0000 (21:28 +0100)
  - this fixes a race condition causing a double free with the to be copied mailpayload

citadel/event_client.c
citadel/modules/c-ares-dns/serv_c-ares-dns.c
citadel/modules/smtp/serv_smtpqueue.c

index b45367d08f71ac784ad9960c2602a34f8fbbe916..c1788a8a6e0dc9f590862efc74b2aa2b90b9cd65 100644 (file)
@@ -340,6 +340,8 @@ void
 IO_postdns_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
 {
        AsyncIO *IO = watcher->data;
+       CtdlLogPrintf(CTDL_DEBUG, "event: %s\n", __FUNCTION__);
+
        IO->PostDNS(IO);
 }
 
index de124f64b2191c4776785dcad3cfc42e2c447ee1..e7a0f57e28aa2e5958096fcdcfbef1370f74721d 100644 (file)
@@ -226,6 +226,7 @@ void QueryCb(void *arg,
                      IO_postdns_callback, 0.0, 0);
        IO->unwind_stack_timeout.data = IO;
        ev_timer_start(event_base, &IO->unwind_stack_timeout);
+       CtdlLogPrintf(CTDL_DEBUG, "C-ARES: %s\n", __FUNCTION__);
 }
 
 void QueryCbDone(AsyncIO *IO)
index 591918ea200b5d3fc551e75e935a034770523841..c071daf2b8f7cdf44ac91d46d525eb42f8c44950 100644 (file)
@@ -117,10 +117,8 @@ int DecreaseQReference(OneQueItem *MyQItem)
 {
        int IDestructQueItem;
 
-       citthread_mutex_lock(&ActiveQItemsLock);
        MyQItem->ActiveDeliveries--;
        IDestructQueItem = MyQItem->ActiveDeliveries == 0;
-       citthread_mutex_unlock(&ActiveQItemsLock);
        return IDestructQueItem;
 }
 
@@ -799,17 +797,18 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        if (MyQItem->ActiveDeliveries > 0)
        {
                int n = MsgCount++;
+               int m = MyQItem->ActiveDeliveries;
                int i = 1;
                Msg = smtp_load_msg(MyQItem, n);
                It = GetNewHashPos(MyQItem->MailQEntries, 0);
-               while ((i <= MyQItem->ActiveDeliveries) && 
+               while ((i <= m) && 
                       (GetNextHashPos(MyQItem->MailQEntries, It, &len, &Key, &vQE)))
                {
                        MailQEntry *ThisItem = vQE;
                        if (ThisItem->Active == 1) {
-                               int KeepBuffers = (i == MyQItem->ActiveDeliveries);
+                               int KeepBuffers = (i == m);
                                if (i > 1) n = MsgCount++;
-                               CtdlLogPrintf(CTDL_DEBUG, "SMTP Queue: Trying <%s>\n", ChrPtr(ThisItem->Recipient));
+                               CtdlLogPrintf(CTDL_DEBUG, "SMTP Queue: Trying <%s> %d / %d \n", ChrPtr(ThisItem->Recipient), i, m);
                                smtp_try(MyQItem, ThisItem, Msg, KeepBuffers, n, RelayUrls);
                                if (KeepBuffers) HaveBuffers = 1;
                                i++;