summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2011-04-27 03:05:26 +0000
committerBenny Prijono <bennylp@teluu.com>2011-04-27 03:05:26 +0000
commit483c05022a57bee19b9e62d3cde9e599dfce03f9 (patch)
tree41a4d1bf85147749777d9fb9ffafb19c345e51cb
parente68df2a248b8af0f6ce1e8b4f81463ecffe77ed7 (diff)
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
-rw-r--r--pjsip/src/pjsip-ua/sip_reg.c15
1 files changed, 13 insertions, 2 deletions
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, &regc_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) {