From: Richard Mudgett Date: Tue, 11 Dec 2012 19:54:50 +0000 (+0000) Subject: Cleanup pbx on exit. X-Git-Tag: 10.12.0-rc2~3^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=797f8fa9d8f6168d4fc13809877b0a3a6fbda8d2;p=thirdparty%2Fasterisk.git Cleanup pbx on exit. * Cleanup CLI commands on exit. * Unreference hints and statecbs containers on exit. (issue ASTERISK-20649) Reported by: Corey Farrell Patches: pbx-cleanup-1_8.patch (license #5909) patch uploaded by Corey Farrell pbx-cleanup-10.patch (license #5909) patch uploaded by Corey Farrell pbx-cleanup-11-trunk.patch (license #5909) patch uploaded by Corey Farrell Modified ........ Merged revisions 377806 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@377807 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/pbx.c b/main/pbx.c index 6dff885329..069031d2f2 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -10716,12 +10716,17 @@ static void unload_pbx(void) if (device_state_sub) { device_state_sub = ast_event_unsubscribe(device_state_sub); } + if (device_state_tps) { + ast_taskprocessor_unreference(device_state_tps); + device_state_tps = NULL; + } /* Unregister builtin applications */ for (x = 0; x < ARRAY_LEN(builtins); x++) { ast_unregister_application(builtins[x].name); } ast_manager_unregister("ShowDialPlan"); + ast_cli_unregister_multiple(pbx_cli, ARRAY_LEN(pbx_cli)); ast_custom_function_unregister(&exception_function); ast_custom_function_unregister(&testtime_function); ast_data_unregister(NULL); @@ -10731,6 +10736,8 @@ int load_pbx(void) { int x; + ast_register_atexit(unload_pbx); + /* Initialize the PBX */ ast_verb(1, "Asterisk PBX Core Initializing\n"); if (!(device_state_tps = ast_taskprocessor_get("pbx-core", 0))) { @@ -10760,7 +10767,6 @@ int load_pbx(void) return -1; } - ast_register_atexit(unload_pbx); return 0; } @@ -11121,17 +11127,23 @@ static int statecbs_cmp(void *obj, void *arg, int flags) return (state_cb->change_cb == change_cb) ? CMP_MATCH | CMP_STOP : 0; } -/*! \internal \brief Clean up resources on Asterisk shutdown */ +/*! + * \internal + * \brief Clean up resources on Asterisk shutdown + */ static void pbx_shutdown(void) { if (hints) { ao2_ref(hints, -1); + hints = NULL; } if (hintdevices) { ao2_ref(hintdevices, -1); + hintdevices = NULL; } if (statecbs) { ao2_ref(statecbs, -1); + statecbs = NULL; } } @@ -11142,5 +11154,6 @@ int ast_pbx_init(void) statecbs = ao2_container_alloc(1, NULL, statecbs_cmp); ast_register_atexit(pbx_shutdown); + return (hints && hintdevices && statecbs) ? 0 : -1; }