Cleanup pbx on exit.
authorRichard Mudgett <rmudgett@digium.com>
Tue, 11 Dec 2012 20:05:32 +0000 (20:05 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 11 Dec 2012 20:05:32 +0000 (20:05 +0000)
* 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
........

Merged revisions 377807 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 377808 from http://svn.asterisk.org/svn/asterisk/branches/11

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@377809 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/pbx.c

index e186b86..d1c8109 100644 (file)
@@ -11747,6 +11747,7 @@ static void unload_pbx(void)
                ast_unregister_application(builtins[x].name);
        }
        ast_manager_unregister("ShowDialPlan");
                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);
        ast_custom_function_unregister(&exception_function);
        ast_custom_function_unregister(&testtime_function);
        ast_data_unregister(NULL);
@@ -11759,6 +11760,8 @@ int load_pbx(void)
 {
        int x;
 
 {
        int x;
 
+       ast_register_atexit(unload_pbx);
+
        /* Initialize the PBX */
        ast_verb(1, "Asterisk PBX Core Initializing\n");
        if (!(extension_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
        /* Initialize the PBX */
        ast_verb(1, "Asterisk PBX Core Initializing\n");
        if (!(extension_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
@@ -11793,7 +11796,6 @@ int load_pbx(void)
                return -1;
        }
 
                return -1;
        }
 
-       ast_register_atexit(unload_pbx);
        return 0;
 }
 
        return 0;
 }
 
@@ -12154,17 +12156,23 @@ static int statecbs_cmp(void *obj, void *arg, int flags)
        return (state_cb->change_cb == change_cb) ? CMP_MATCH | CMP_STOP : 0;
 }
 
        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);
 static void pbx_shutdown(void)
 {
        if (hints) {
                ao2_ref(hints, -1);
+               hints = NULL;
        }
        if (hintdevices) {
                ao2_ref(hintdevices, -1);
        }
        if (hintdevices) {
                ao2_ref(hintdevices, -1);
+               hintdevices = NULL;
        }
        if (statecbs) {
                ao2_ref(statecbs, -1);
        }
        if (statecbs) {
                ao2_ref(statecbs, -1);
+               statecbs = NULL;
        }
 }
 
        }
 }
 
@@ -12175,5 +12183,6 @@ int ast_pbx_init(void)
        statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);
 
        ast_register_atexit(pbx_shutdown);
        statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);
 
        ast_register_atexit(pbx_shutdown);
+
        return (hints && hintdevices && statecbs) ? 0 : -1;
 }
        return (hints && hintdevices && statecbs) ? 0 : -1;
 }