Skip to content

Commit

Permalink
lib-smtp: server: recipient: Prevent reference counting from within d…
Browse files Browse the repository at this point in the history
…estroy hook.
  • Loading branch information
stephanbosch committed Nov 1, 2018
1 parent 144b638 commit 529eb8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib-smtp/smtp-server-private.h
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/lib-smtp/smtp-server-recipient.c
Expand Up @@ -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++;
}
Expand All @@ -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);
Expand Down

0 comments on commit 529eb8a

Please sign in to comment.