]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: server: recipient: Prevent reference counting from within destroy hook.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 31 Oct 2018 23:58:47 +0000 (00:58 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 12 Feb 2019 13:41:49 +0000 (15:41 +0200)
src/lib-smtp/smtp-server-private.h
src/lib-smtp/smtp-server-recipient.c

index 8181a41fb8841ba63bfea5fc05fc98a0acbc62d4..da4a090f9b5bdf326c8be169268db894889d6c29 100644 (file)
@@ -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 {
index 76080149d3dad405659b44899f26131638380585..24a752c85cc3d58fe5518388c91c33da84af4052 100644 (file)
@@ -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);