From 6542abd4a0800eada4a9e6696be23e6faf361c35 Mon Sep 17 00:00:00 2001 From: Maximilian Fridrich Date: Tue, 9 Apr 2024 11:45:26 +0200 Subject: [PATCH] sess,request: deref request and ctrans immediately if no provisional response was received for the request. --- include/re_sip.h | 1 + src/sip/request.c | 17 ++++++++++++++++- src/sipsess/sess.c | 9 +++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/re_sip.h b/include/re_sip.h index e374f215c..5e892721a 100644 --- a/include/re_sip.h +++ b/include/re_sip.h @@ -344,6 +344,7 @@ int sip_drequestf(struct sip_request **reqp, struct sip *sip, bool stateful, void sip_request_cancel(struct sip_request *req); bool sip_request_loops(struct sip_loopstate *ls, uint16_t scode); void sip_loopstate_reset(struct sip_loopstate *ls); +bool sip_request_provrecv(const struct sip_request *req); /* reply */ diff --git a/src/sip/request.c b/src/sip/request.c index cb60a8801..02b45d740 100644 --- a/src/sip/request.c +++ b/src/sip/request.c @@ -970,13 +970,28 @@ void sip_request_cancel(struct sip_request *req) req->canceled = true; - if (!req->provrecv) + if (!req->provrecv) { + req->ct = mem_deref(req->ct); return; + } (void)sip_ctrans_cancel(req->ct); } +/** + * Check if a provisional response was received for a SIP Request + * + * @param req SIP Request + * + * @return True if a provisional response was received, false otherwise + */ +bool sip_request_provrecv(const struct sip_request *req) +{ + return req ? req->provrecv : false; +} + + void sip_request_close(struct sip *sip) { if (!sip) diff --git a/src/sipsess/sess.c b/src/sipsess/sess.c index f394ec92c..18123aa91 100644 --- a/src/sipsess/sess.c +++ b/src/sipsess/sess.c @@ -85,8 +85,13 @@ static bool termwait(struct sipsess *sess) if (sess->req) { sip_request_cancel(sess->req); - mem_ref(sess); - wait = true; + if (!sip_request_provrecv(sess->req)) { + sess->req = mem_deref(sess->req); + } + else { + mem_ref(sess); + wait = true; + } } if (sess->replyl.head) {