From 529eb8a5f118d54250055000afb237c6bd2afd75 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Thu, 1 Nov 2018 00:58:47 +0100 Subject: [PATCH] lib-smtp: server: recipient: Prevent reference counting from within destroy hook. --- src/lib-smtp/smtp-server-private.h | 2 ++ src/lib-smtp/smtp-server-recipient.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/lib-smtp/smtp-server-private.h b/src/lib-smtp/smtp-server-private.h index 8181a41fb8..da4a090f9b 100644 --- a/src/lib-smtp/smtp-server-private.h +++ b/src/lib-smtp/smtp-server-private.h @@ -116,6 +116,8 @@ struct smtp_server_recipient_private { int refcount; struct smtp_server_recipient_hook *hooks_head, *hooks_tail; + + bool destroying:1; }; struct smtp_server_state_data { diff --git a/src/lib-smtp/smtp-server-recipient.c b/src/lib-smtp/smtp-server-recipient.c index 76080149d3..24a752c85c 100644 --- a/src/lib-smtp/smtp-server-recipient.c +++ b/src/lib-smtp/smtp-server-recipient.c @@ -33,6 +33,8 @@ void smtp_server_recipient_ref(struct smtp_server_recipient *rcpt) struct smtp_server_recipient_private *prcpt = (struct smtp_server_recipient_private *)rcpt; + if (prcpt->destroying) + return; i_assert(prcpt->refcount > 0); prcpt->refcount++; } @@ -47,10 +49,13 @@ bool smtp_server_recipient_unref(struct smtp_server_recipient **_rcpt) if (rcpt == NULL) return FALSE; + if (prcpt->destroying) + return FALSE; i_assert(prcpt->refcount > 0); if (--prcpt->refcount > 0) return TRUE; + prcpt->destroying = TRUE; smtp_server_recipient_call_hooks( rcpt, SMTP_SERVER_RECIPIENT_HOOK_DESTROY); -- 2.47.3