Skip to content

Commit

Permalink
transp: deref qent only if qentp is not set
Browse files Browse the repository at this point in the history
If qentp is set, the caller of sip_transp_send is responsible for
derefing qent.
  • Loading branch information
maximilianfridrich committed Jan 30, 2024
1 parent bb7eeea commit 0d7277b
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = qent->qentp ? true : false;

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);
Expand Down Expand Up @@ -618,13 +617,9 @@ static void tcp_estab_handler(void *arg)
while (le) {

struct sip_connqent *qent = le->data;
bool qentp_set = qent->qentp ? true : false;
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,
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit 0d7277b

Please sign in to comment.