From 7d69da12d3c52fbd1ebea6f4a6a56d9595c05078 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 28 Mar 2012 07:32:42 +0000 Subject: Re #1466: Moved down the atexit callbacks execution in pjmedia & pjsip endpoints to the very end of endpoint destroy sequence. git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@3988 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/endpoint.h | 5 ++++- pjmedia/src/pjmedia/endpoint.c | 15 ++++++++------- pjsip/include/pjsip/sip_endpoint.h | 5 ++++- pjsip/src/pjsip/sip_endpoint.c | 14 +++++++------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pjmedia/include/pjmedia/endpoint.h b/pjmedia/include/pjmedia/endpoint.h index 2455bcea..108dee62 100644 --- a/pjmedia/include/pjmedia/endpoint.h +++ b/pjmedia/include/pjmedia/endpoint.h @@ -212,7 +212,10 @@ PJ_DECL(pj_status_t) pjmedia_endpt_dump(pjmedia_endpt *endpt); /** * Register cleanup function to be called by media endpoint when - * #pjmedia_endpt_destroy() is called. + * #pjmedia_endpt_destroy() is called. Note that application should not + * use or access any endpoint resource (such as pool, ioqueue) from within + * the callback as such resource may have been released when the callback + * function is invoked. * * @param endpt The media endpoint. * @param func The function to be registered. diff --git a/pjmedia/src/pjmedia/endpoint.c b/pjmedia/src/pjmedia/endpoint.c index 43ed4ccf..bf9d3c91 100644 --- a/pjmedia/src/pjmedia/endpoint.c +++ b/pjmedia/src/pjmedia/endpoint.c @@ -219,13 +219,6 @@ PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt) } } - /* Call all registered exit callbacks */ - ecb = endpt->exit_cb_list.next; - while (ecb != &endpt->exit_cb_list) { - (*ecb->func)(endpt); - ecb = ecb->next; - } - /* Destroy internal ioqueue */ if (endpt->ioqueue && endpt->own_ioqueue) { pj_ioqueue_destroy(endpt->ioqueue); @@ -236,6 +229,14 @@ PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt) pjmedia_codec_mgr_destroy(&endpt->codec_mgr); pjmedia_aud_subsys_shutdown(); + + /* Call all registered exit callbacks */ + ecb = endpt->exit_cb_list.next; + while (ecb != &endpt->exit_cb_list) { + (*ecb->func)(endpt); + ecb = ecb->next; + } + pj_pool_release (endpt->pool); return PJ_SUCCESS; diff --git a/pjsip/include/pjsip/sip_endpoint.h b/pjsip/include/pjsip/sip_endpoint.h index bc652e60..c6cf6d65 100644 --- a/pjsip/include/pjsip/sip_endpoint.h +++ b/pjsip/include/pjsip/sip_endpoint.h @@ -520,7 +520,10 @@ PJ_DECL(void) pjsip_endpt_dump( pjsip_endpoint *endpt, pj_bool_t detail ); /** * Register cleanup function to be called by SIP endpoint when - * #pjsip_endpt_destroy() is called. + * #pjsip_endpt_destroy() is called. Note that application should not + * use or access any endpoint resource (such as pool, ioqueue, timer heap) + * from within the callback as such resource may have been released when + * the callback function is invoked. * * @param endpt The SIP endpoint. * @param func The function to be registered. diff --git a/pjsip/src/pjsip/sip_endpoint.c b/pjsip/src/pjsip/sip_endpoint.c index 0125ae39..2831ea7d 100644 --- a/pjsip/src/pjsip/sip_endpoint.c +++ b/pjsip/src/pjsip/sip_endpoint.c @@ -578,13 +578,6 @@ PJ_DEF(void) pjsip_endpt_destroy(pjsip_endpoint *endpt) PJ_LOG(5, (THIS_FILE, "Destroying endpoing instance..")); - /* Call all registered exit callbacks */ - ecb = endpt->exit_cb_list.next; - while (ecb != &endpt->exit_cb_list) { - (*ecb->func)(endpt); - ecb = ecb->next; - } - /* Phase 1: stop all modules */ mod = endpt->module_list.prev; while (mod != &endpt->module_list) { @@ -615,6 +608,13 @@ PJ_DEF(void) pjsip_endpt_destroy(pjsip_endpoint *endpt) /* Destroy timer heap */ pj_timer_heap_destroy(endpt->timer_heap); + /* Call all registered exit callbacks */ + ecb = endpt->exit_cb_list.next; + while (ecb != &endpt->exit_cb_list) { + (*ecb->func)(endpt); + ecb = ecb->next; + } + /* Delete endpoint mutex. */ pj_mutex_destroy(endpt->mutex); -- cgit v1.2.3