]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: client: transaction: Hold a reference to the transaction while calling...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 2 Nov 2018 09:08:26 +0000 (10:08 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 12 Feb 2019 13:41:52 +0000 (15:41 +0200)
This fixes memory problems when the callback inadvertently gets the transaction destroyed.

src/lib-smtp/smtp-client-transaction.c

index f882f43d0bd196d2e66ad4773640927bc8e92959..f3cb974b8de3d52ed25f9fed53ab953adc451bf4 100644 (file)
@@ -802,7 +802,18 @@ smtp_client_transaction_rcpt_cb(const struct smtp_reply *reply,
        else
                smtp_client_transaction_rcpt_denied(&rcpt);
 
-       rcpt_callback(reply, context);
+       /* call the callback */
+       {
+               enum smtp_client_transaction_state state;
+               struct smtp_client_transaction *tmp_trans = trans;
+
+               smtp_client_transaction_ref(tmp_trans);
+               rcpt_callback(reply, context);
+               state = trans->state;
+               smtp_client_transaction_unref(&tmp_trans);
+               if (state >= SMTP_CLIENT_TRANSACTION_STATE_FINISHED)
+                       return;
+       }
 
        smtp_client_transaction_try_complete(trans);
 }