Index: main/sorcery.c =================================================================== --- main/sorcery.c (revision 391701) +++ main/sorcery.c (working copy) @@ -238,6 +238,19 @@ return !strcmp(wizard1->name, flags & OBJ_KEY ? name : wizard2->name) ? CMP_MATCH | CMP_STOP : 0; } +/*! \brief Cleanup function */ +static void sorcery_exit(void) +{ + ast_threadpool_shutdown(threadpool); + threadpool = NULL; +} + +/*! \brief Cleanup function for graceful shutdowns */ +static void sorcery_cleanup(void) +{ + ao2_cleanup(wizards); +} + int ast_sorcery_init(void) { struct ast_threadpool_options options = { @@ -255,9 +268,13 @@ if (!(wizards = ao2_container_alloc(WIZARD_BUCKETS, sorcery_wizard_hash, sorcery_wizard_cmp))) { ast_threadpool_shutdown(threadpool); + threadpool = NULL; return -1; } + ast_register_cleanup(sorcery_cleanup); + ast_register_atexit(sorcery_exit); + return 0; }