]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix graceful shutdown crash.
authorDavid M. Lee <dlee@digium.com>
Fri, 30 Aug 2013 20:58:59 +0000 (20:58 +0000)
committerDavid M. Lee <dlee@digium.com>
Fri, 30 Aug 2013 20:58:59 +0000 (20:58 +0000)
The cleanup code for optional_api needs to happen after all of the optional
API users and providers have unused/unprovided. Unfortunately, regsitering the
atexit() handler at the beginning of main() isn't soon enough, since module
destructors run after that.
........

Merged revisions 398149 from http://svn.asterisk.org/svn/asterisk/branches/12

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

include/asterisk/optional_api.h
main/asterisk.c
main/optional_api.c

index 7d66d2e47689e641357e07d112d41a0851b4d8d6..394aed0e4c01a21b8f078118ef7c64b42fcff02e 100644 (file)
@@ -176,14 +176,6 @@ void ast_optional_api_use(const char *symname, ast_optional_fn *optional_ref,
 void ast_optional_api_unuse(const char *symname, ast_optional_fn *optional_ref,
        const char *module);
 
-/*!
- * \brief Call at exit to clean up optional_api internals.
- *
- * Since the optional_api code might run before main() starts, it can't safely
- * register its own cleanup handlers. That has to be done within main().
- */
-void optional_api_cleanup(void);
-
 #define AST_OPTIONAL_API_NAME(name) __##name
 
 #if defined(AST_API_MODULE)
index 395d0cc18d57946c364a6006a0b3aeaf082918a6..3b08d76c56903de1ffec0c0b41833e539d1e3f44 100644 (file)
@@ -247,7 +247,6 @@ int daemon(int, int);  /* defined in libresolv of all places */
 #include "asterisk/stasis_endpoints.h"
 #include "asterisk/stasis_system.h"
 #include "asterisk/security_events.h"
-#include "asterisk/optional_api.h"
 
 #include "../defaults.h"
 
@@ -4169,10 +4168,6 @@ int main(int argc, char *argv[])
                        ast_el_read_history(filename);
        }
 
-#if defined(OPTIONAL_API)
-       ast_register_cleanup(optional_api_cleanup);
-#endif
-
        ast_json_init();
        ast_ulaw_init();
        ast_alaw_init();
index f48fe11a11995112aa2755580d3a7cd74d6962a8..9c96fa6466596a4ff8204e3a9807fee8020dc31e 100644 (file)
@@ -158,18 +158,8 @@ struct {
        size_t len;
 } apis;
 
-void optional_api_cleanup(void)
-{
-       while (apis.len--) {
-               optional_api_destroy(apis.list[apis.len]);
-       }
-       free(apis.list);
-       apis.list = NULL;
-       apis.maxlen = 0;
-}
-
 /*!
- * \brief Gets (or creates) the \ref optional_api for the give function.
+ * \brief Gets (or creates) the \ref optional_api for the given function.
  *
  * \param sysname Name of the function to look up.
  * \return Corresponding \ref optional_api.
@@ -181,9 +171,11 @@ static struct optional_api *get_api(const char *symname)
        size_t i;
 
        /* Find one, if we already have it */
-       for (i = 0; i < apis.len; ++i) {
-               if (strcmp(symname, apis.list[i]->symname) == 0) {
-                       return apis.list[i];
+       if (apis.list) {
+               for (i = 0; i < apis.len; ++i) {
+                       if (strcmp(symname, apis.list[i]->symname) == 0) {
+                               return apis.list[i];
+                       }
                }
        }