summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2012-04-11 09:41:25 +0000
committerBenny Prijono <bennylp@teluu.com>2012-04-11 09:41:25 +0000
commit78ce50707aff32caa195be402721001d51dba2c0 (patch)
tree10e27f86a863393c2281ba6e1005c833405a6856
parentc4cf3952e436987946dd8d7626b9cf0c4d75656a (diff)
More re #1481: Destroying the regc may lead to dangling binding in the register, so instead of destroying the regc, instruct it to release the transport instead
git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@4037 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsip-ua/sip_regc.h13
-rw-r--r--pjsip/src/pjsip-ua/sip_reg.c15
-rw-r--r--pjsip/src/pjsua-lib/pjsua_acc.c7
3 files changed, 31 insertions, 4 deletions
diff --git a/pjsip/include/pjsip-ua/sip_regc.h b/pjsip/include/pjsip-ua/sip_regc.h
index 4ef4bbaa..c2aec0c8 100644
--- a/pjsip/include/pjsip-ua/sip_regc.h
+++ b/pjsip/include/pjsip-ua/sip_regc.h
@@ -265,6 +265,19 @@ PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc,
PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc,
const pjsip_tpselector *sel);
+/**
+ * Release the reference to current transport being used by the regc, if any.
+ * The regc keeps the reference to the last transport being used in order
+ * to prevent it from being destroyed. In some situation however, such as
+ * when the transport is disconnected, it is necessary to instruct the
+ * regc to release this reference so that the transport can be destroyed.
+ * See https://trac.pjsip.org/repos/ticket/1481 for background info.
+ *
+ * @param regc The client registration instance.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc);
/**
* Add headers to be added to outgoing REGISTER requests.
diff --git a/pjsip/src/pjsip-ua/sip_reg.c b/pjsip/src/pjsip-ua/sip_reg.c
index 750e22f7..c02c17bb 100644
--- a/pjsip/src/pjsip-ua/sip_reg.c
+++ b/pjsip/src/pjsip-ua/sip_reg.c
@@ -440,6 +440,17 @@ PJ_DEF(pj_status_t) pjsip_regc_set_transport( pjsip_regc *regc,
return PJ_SUCCESS;
}
+/* Release transport */
+PJ_DEF(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc)
+{
+ PJ_ASSERT_RETURN(regc, PJ_EINVAL);
+ if (regc->last_transport) {
+ pjsip_transport_dec_ref(regc->last_transport);
+ regc->last_transport = NULL;
+ }
+ return PJ_SUCCESS;
+}
+
PJ_DEF(pj_status_t) pjsip_regc_add_headers( pjsip_regc *regc,
const pjsip_hdr *hdr_list)
@@ -1269,7 +1280,9 @@ PJ_DEF(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata)
pj_lock_acquire(regc->lock);
/* Get last transport used and add reference to it */
- if (tdata->tp_info.transport != regc->last_transport) {
+ if (tdata->tp_info.transport != regc->last_transport &&
+ status==PJ_SUCCESS)
+ {
if (regc->last_transport) {
pjsip_transport_dec_ref(regc->last_transport);
regc->last_transport = NULL;
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index a0a5d81d..4758f391 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -2821,11 +2821,12 @@ void pjsua_acc_on_tp_state_changed(pjsip_transport *tp,
continue;
}
- /* Destroy regc to release transport immediately */
+ /* Release regc transport immediately
+ * See https://trac.pjsip.org/repos/ticket/1481
+ */
if (pjsua_var.acc[i].regc) {
- pjsip_regc_destroy(pjsua_var.acc[i].regc);
+ pjsip_regc_release_transport(pjsua_var.acc[i].regc);
}
- pjsua_var.acc[i].regc = NULL;
/* Schedule reregistration for this account */
schedule_reregistration(acc);