From 483c05022a57bee19b9e62d3cde9e599dfce03f9 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 27 Apr 2011 03:05:26 +0000 Subject: Fixed #1247: Deadlock potential in sip_regc.c if sending fails (thank you Alejandro Orellana for the report) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3545 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsip-ua/sip_reg.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'pjsip/src') diff --git a/pjsip/src/pjsip-ua/sip_reg.c b/pjsip/src/pjsip-ua/sip_reg.c index bb7e50b7..ef8263e3 100644 --- a/pjsip/src/pjsip-ua/sip_reg.c +++ b/pjsip/src/pjsip-ua/sip_reg.c @@ -991,7 +991,7 @@ static pj_int32_t calculate_response_expiration(const pjsip_regc *regc, return expiration; } -static void tsx_callback(void *token, pjsip_event *event) +static void regc_tsx_callback(void *token, pjsip_event *event) { pj_status_t status; pjsip_regc *regc = (pjsip_regc*) token; @@ -1251,12 +1251,23 @@ PJ_DEF(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata) */ pjsip_tx_data_add_ref(tdata); + /* Need to unlock the regc temporarily while sending the message to + * prevent deadlock (https://trac.pjsip.org/repos/ticket/1247). + * It should be safe to do this since the regc's refcount has been + * incremented. + */ + pj_lock_release(regc->lock); + + /* Now send the message */ status = pjsip_endpt_send_request(regc->endpt, tdata, REGC_TSX_TIMEOUT, - regc, &tsx_callback); + regc, ®c_tsx_callback); if (status!=PJ_SUCCESS) { PJ_LOG(4,(THIS_FILE, "Error sending request, status=%d", status)); } + /* Reacquire the lock */ + pj_lock_acquire(regc->lock); + /* Get last transport used and add reference to it */ if (tdata->tp_info.transport != regc->last_transport) { if (regc->last_transport) { -- cgit v1.2.3