Skip to content

Commit

Permalink
lib-smtp: client: transaction: Prevent calling callbacks after smtp_c…
Browse files Browse the repository at this point in the history
…lient_transaction_destroy().
  • Loading branch information
stephanbosch authored and cmouse committed Oct 10, 2018
1 parent 4bee7b2 commit cc9d4ca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib-smtp/smtp-client-transaction.c
Expand Up @@ -202,6 +202,7 @@ smtp_client_transaction_finish(struct smtp_client_transaction *trans)
i_assert(trans->to_send == NULL);

trans->state = SMTP_CLIENT_TRANSACTION_STATE_FINISHED;
i_assert(trans->callback != NULL);
trans->callback(trans->context);

if (!trans->submitted_data)
Expand Down Expand Up @@ -257,6 +258,7 @@ void smtp_client_transaction_abort(struct smtp_client_transaction *trans)
smtp_client_transaction_debug(trans, "Aborted");

trans->state = SMTP_CLIENT_TRANSACTION_STATE_ABORTED;
i_assert(trans->callback != NULL);
trans->callback(trans->context);

smtp_client_transaction_unref(&trans);
Expand Down Expand Up @@ -293,12 +295,29 @@ void smtp_client_transaction_unref(struct smtp_client_transaction **_trans)
void smtp_client_transaction_destroy(struct smtp_client_transaction **_trans)
{
struct smtp_client_transaction *trans = *_trans;
struct smtp_client_transaction_rcpt **rcpts;
unsigned int count, i;

*_trans = NULL;

smtp_client_transaction_ref(trans);
smtp_client_transaction_abort(trans);

/* Make sure this transaction doesn't produce any more callbacks.
We cannot fully abort (destroy) these commands, as this may be
called from a callback. */
if (trans->cmd_mail_from != NULL)
smtp_client_command_drop_callback(trans->cmd_mail_from);
rcpts = array_get_modifiable(&trans->rcpts_pending, &count);
for (i = 0; i < count; i++) {
if (rcpts[i]->cmd_rcpt_to != NULL)
smtp_client_command_drop_callback(rcpts[i]->cmd_rcpt_to);
}
if (trans->cmd_data != NULL)
smtp_client_command_drop_callback(trans->cmd_data);
if (trans->cmd_plug != NULL)
smtp_client_command_abort(&trans->cmd_plug);

if (trans->state < SMTP_CLIENT_TRANSACTION_STATE_FINISHED) {
struct smtp_client_transaction *trans_tmp = trans;

Expand Down

0 comments on commit cc9d4ca

Please sign in to comment.