From d28ab55352fc1c4a9ee0e91741bda10ea8d5acb6 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 28 Mar 2012 07:49:54 +0000 Subject: Fix #1470: Make sure the transaction layer module is unloaded when SIP endpoint is destroyed, by rescheduling the unload (using SIP endpoint atexit callback) after unload failure due to any pending/undestroyed transaction. git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@3989 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsip/sip_transaction.c | 43 ++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c index 702914be..7962800c 100644 --- a/pjsip/src/pjsip/sip_transaction.c +++ b/pjsip/src/pjsip/sip_transaction.c @@ -714,23 +714,17 @@ static pj_status_t mod_tsx_layer_stop(void) } pj_mutex_unlock(mod_tsx_layer.mutex); + + PJ_LOG(4,(THIS_FILE, "Stopped transaction layer module")); + return PJ_SUCCESS; } -/* This module callback is called when module is being unloaded by - * endpoint. - */ -static pj_status_t mod_tsx_layer_unload(void) +/* Destroy this module */ +static void tsx_layer_destroy(pjsip_endpoint *endpt) { - /* Only self destroy when there's no transaction in the table. - * Transaction may refuse to destroy when it has pending - * transmission. If we destroy the module now, application will - * crash when the pending transaction finally got error response - * from transport and when it tries to unregister itself. - */ - if (pj_hash_count(mod_tsx_layer.htable) != 0) - return PJ_EBUSY; + PJ_UNUSED_ARG(endpt); /* Destroy mutex. */ pj_mutex_destroy(mod_tsx_layer.mutex); @@ -745,6 +739,31 @@ static pj_status_t mod_tsx_layer_unload(void) mod_tsx_layer.endpt = NULL; PJ_LOG(4,(THIS_FILE, "Transaction layer module destroyed")); +} + + +/* This module callback is called when module is being unloaded by + * endpoint. + */ +static pj_status_t mod_tsx_layer_unload(void) +{ + /* Only self destroy when there's no transaction in the table. + * Transaction may refuse to destroy when it has pending + * transmission. If we destroy the module now, application will + * crash when the pending transaction finally got error response + * from transport and when it tries to unregister itself. + */ + if (pj_hash_count(mod_tsx_layer.htable) != 0) { + if (pjsip_endpt_atexit(mod_tsx_layer.endpt, &tsx_layer_destroy) != + PJ_SUCCESS) + { + PJ_LOG(3,(THIS_FILE, "Failed to register transaction layer " + "module destroy.")); + } + return PJ_EBUSY; + } + + tsx_layer_destroy(mod_tsx_layer.endpt); return PJ_SUCCESS; } -- cgit v1.2.3