diff --git a/src/pkt_normalizer.c b/src/pkt_normalizer.c index 82aafdb63..16da36f33 100644 --- a/src/pkt_normalizer.c +++ b/src/pkt_normalizer.c @@ -108,6 +108,17 @@ void pn_deinit(struct PKTNORM* pn) { queue_entry_free(pn->recvpart); } + // Cancel waiter and clear callbacks on ETCP queues to prevent use-after-free + // during etcp_connection_close() when drain_and_free_fragment_queue() is called + if (pn->etcp) { + if (pn->etcp->input_queue) { + queue_cancel_wait(pn->etcp->input_queue, &pn->etcp->input_queue->waiter); + } + if (pn->etcp->output_queue) { + queue_set_callback(pn->etcp->output_queue, NULL, NULL); + } + } + free(pn); }