From be967a283579c6260f98bedbe01fc784aa56e10f Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 14 Jul 2008 09:55:01 +0000 Subject: Related to ticket #518: only destroy the account and buddy pools after busy_sleep() is done, otherwise when unregistration callback is called, the callback will access accounts which are no longer valid because the pool has been destroyed git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2134 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsua-lib/pjsua_core.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'pjsip') diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 384e332b..d871b6fc 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -1069,15 +1069,7 @@ PJ_DEF(pj_status_t) pjsua_destroy(void) /* Terminate all presence subscriptions. */ pjsua_pres_shutdown(); - /* Destroy pool in the buddy object */ - for (i=0; i<(int)PJ_ARRAY_SIZE(pjsua_var.buddy); ++i) { - if (pjsua_var.buddy[i].pool) { - pj_pool_release(pjsua_var.buddy[i].pool); - pjsua_var.buddy[i].pool = NULL; - } - } - - /* Destroy accounts */ + /* Unregister all accounts */ for (i=0; i<(int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { if (!pjsua_var.acc[i].valid) continue; @@ -1085,11 +1077,6 @@ PJ_DEF(pj_status_t) pjsua_destroy(void) if (pjsua_var.acc[i].regc) { pjsua_acc_set_registration(i, PJ_FALSE); } - - if (pjsua_var.acc[i].pool) { - pj_pool_release(pjsua_var.acc[i].pool); - pjsua_var.acc[i].pool = NULL; - } } } @@ -1104,6 +1091,24 @@ PJ_DEF(pj_status_t) pjsua_destroy(void) PJ_LOG(4,(THIS_FILE, "Shutting down...")); busy_sleep(1000); + PJ_LOG(4,(THIS_FILE, "Destroying...")); + + /* Destroy pool in the buddy object */ + for (i=0; i<(int)PJ_ARRAY_SIZE(pjsua_var.buddy); ++i) { + if (pjsua_var.buddy[i].pool) { + pj_pool_release(pjsua_var.buddy[i].pool); + pjsua_var.buddy[i].pool = NULL; + } + } + + /* Destroy accounts */ + for (i=0; i<(int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { + if (pjsua_var.acc[i].pool) { + pj_pool_release(pjsua_var.acc[i].pool); + pjsua_var.acc[i].pool = NULL; + } + } + pjsip_endpt_destroy(pjsua_var.endpt); pjsua_var.endpt = NULL; } -- cgit v1.2.3