summaryrefslogtreecommitdiff
path: root/res/res_pjsip.c
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2018-02-06 10:28:49 -0700
committerGeorge Joseph <gjoseph@digium.com>2018-02-21 08:14:47 -0700
commitde871515ba06e3c3e6343a09652d3079c3706215 (patch)
tree4d7e51b85f690468758804dab17f69746a37a4dc /res/res_pjsip.c
parentc53d8dcb68751f499df31f0c07c3be7ccd02fa68 (diff)
AST-2018-005: Fix tdata leaks when calling pjsip_endpt_send_response(2)
pjsip_distributor: authenticate() creates a tdata and uses it to send a challenge or failure response. When pjsip_endpt_send_response2() succeeds, it automatically decrements the tdata ref count but when it fails, it doesn't. Since we weren't checking for a return status, we weren't decrementing the count ourselves on error and were therefore leaking tdatas. res_pjsip_session: session_reinvite_on_rx_request wasn't decrementing the ref count if an error happened while sending a 491 response. pre_session_setup wasn't decrementing the ref count if while sending an error after a pjsip_inv_verify_request failure. res_pjsip: ast_sip_send_response wasn't decrementing the ref count on error. ASTERISK-27618 Reported By: Sandro Gauci Change-Id: Iab33a6c7b6fba96148ed465b690ba8534ac961bf
Diffstat (limited to 'res/res_pjsip.c')
-rw-r--r--res/res_pjsip.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 79e6cc20b..df4dd47c6 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -4722,9 +4722,15 @@ static void supplement_outgoing_response(pjsip_tx_data *tdata, struct ast_sip_en
int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
{
+ pj_status_t status;
+
supplement_outgoing_response(tdata, sip_endpoint);
+ status = pjsip_endpt_send_response(ast_sip_get_pjsip_endpoint(), res_addr, tdata, NULL, NULL);
+ if (status != PJ_SUCCESS) {
+ pjsip_tx_data_dec_ref(tdata);
+ }
- return pjsip_endpt_send_response(ast_sip_get_pjsip_endpoint(), res_addr, tdata, NULL, NULL);
+ return status == PJ_SUCCESS ? 0 : -1;
}
int ast_sip_send_stateful_response(pjsip_rx_data *rdata, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)