From 84cd2634c086829291eb87eaee4f81c0c03f9fce Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 30 Jan 2011 21:28:35 +0100 Subject: [PATCH] libev migration - copy valus we use for loop control before we hand it off into the libevent queue - this fixes a race condition causing a double free with the to be copied mailpayload --- citadel/event_client.c | 2 ++ citadel/modules/c-ares-dns/serv_c-ares-dns.c | 1 + citadel/modules/smtp/serv_smtpqueue.c | 9 ++++----- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/citadel/event_client.c b/citadel/event_client.c index b45367d08..c1788a8a6 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -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); } diff --git a/citadel/modules/c-ares-dns/serv_c-ares-dns.c b/citadel/modules/c-ares-dns/serv_c-ares-dns.c index de124f64b..e7a0f57e2 100644 --- a/citadel/modules/c-ares-dns/serv_c-ares-dns.c +++ b/citadel/modules/c-ares-dns/serv_c-ares-dns.c @@ -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) diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index 591918ea2..c071daf2b 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -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++; -- 2.30.2