Index: main/pbx.c =================================================================== --- main/pbx.c (revision 375799) +++ main/pbx.c (working copy) @@ -10313,12 +10313,17 @@ 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); @@ -10718,10 +10723,24 @@ return (state_cb->change_cb == change_cb) ? CMP_MATCH | CMP_STOP : 0; } +static void pbx_shutdown(void) +{ + if (hints) { + ao2_ref(hints, -1); + hints = NULL; + } + if (statecbs) { + ao2_ref(statecbs, -1); + statecbs = NULL; + } +} + int ast_pbx_init(void) { hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp); statecbs = ao2_container_alloc(1, NULL, statecbs_cmp); + ast_register_atexit(pbx_shutdown); + return (hints && statecbs) ? 0 : -1; }