From c99c1532345f930dd7fbe70afb48f633c5f7ea5e Mon Sep 17 00:00:00 2001 From: Maximilian Fridrich Date: Mon, 29 Jan 2024 10:46:29 +0100 Subject: [PATCH] transp: deref qent only if qentp is not set If qentp is set, the caller of sip_transp_send is responsible for derefing qent. --- src/sip/transp.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/sip/transp.c b/src/sip/transp.c index ada515522..68c4c97af 100644 --- a/src/sip/transp.c +++ b/src/sip/transp.c @@ -261,15 +261,14 @@ static void conn_close(struct sip_conn *conn, int err) struct sip_connqent *qent = le->data; le = le->next; - - if (qent->qentp) { - *qent->qentp = NULL; - qent->qentp = NULL; - } + bool qentp_set = (bool)qent->qentp; qent->transph(err, qent->arg); - list_unlink(&qent->le); - mem_deref(qent); + + if (!qentp_set) { + list_unlink(&qent->le); + mem_deref(qent); + } } sip_keepalive_signal(&conn->kal, err); @@ -618,13 +617,9 @@ static void tcp_estab_handler(void *arg) while (le) { struct sip_connqent *qent = le->data; + bool qentp_set = (bool)qent->qentp; le = le->next; - if (qent->qentp) { - *qent->qentp = NULL; - qent->qentp = NULL; - } - trace_send(conn->sip, conn->sc ? SIP_TRANSP_TLS : SIP_TRANSP_TCP, conn, @@ -634,8 +629,10 @@ static void tcp_estab_handler(void *arg) if (err) qent->transph(err, qent->arg); - list_unlink(&qent->le); - mem_deref(qent); + if (!qentp_set) { + list_unlink(&qent->le); + mem_deref(qent); + } } } @@ -896,13 +893,9 @@ static void websock_estab_handler(void *arg) while (le) { struct sip_connqent *qent = le->data; + bool qentp_set = (bool)qent->qentp; le = le->next; - if (qent->qentp) { - *qent->qentp = NULL; - qent->qentp = NULL; - } - trace_send(conn->sip, conn->tp, conn, @@ -917,8 +910,10 @@ static void websock_estab_handler(void *arg) if (err) qent->transph(err, qent->arg); - list_unlink(&qent->le); - mem_deref(qent); + if (!qentp_set) { + list_unlink(&qent->le); + mem_deref(qent); + } } }