summaryrefslogtreecommitdiff
path: root/res/res_sorcery_memory_cache.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-10-01 14:27:34 -0500
committerRichard Mudgett <rmudgett@digium.com>2015-10-01 17:25:37 -0500
commitced0a2d71b690f24026392bcfbbe4c36eb8d4dff (patch)
tree9c377e1ca2fd952bdf0c49c515cb8e525104c388 /res/res_sorcery_memory_cache.c
parentcc279eea11853ad90605775a63d58a1cab88f96c (diff)
res_sorcery_memory_cache.c: Shutdown in a less crash potential order.
Basically you should shutdown in the opposite order of how you setup since later setup pieces likely depend on earlier setup pieces. e.g., Registering your external API with the rest of the system should be the last thing setup and the first thing unregistered during shutdown. Change-Id: I5715765b723100c8d3c2642e9e72cc7ad5ad115e
Diffstat (limited to 'res/res_sorcery_memory_cache.c')
-rw-r--r--res/res_sorcery_memory_cache.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c
index 620c34648..bc385b4ae 100644
--- a/res/res_sorcery_memory_cache.c
+++ b/res/res_sorcery_memory_cache.c
@@ -2480,22 +2480,6 @@ cleanup:
static int unload_module(void)
{
- if (sched) {
- ast_sched_context_destroy(sched);
- sched = NULL;
- }
-
- ao2_cleanup(caches);
-
- ast_sorcery_wizard_unregister(&memory_cache_object_wizard);
-
- ast_cli_unregister_multiple(cli_memory_cache, ARRAY_LEN(cli_memory_cache));
-
- ast_manager_unregister("SorceryMemoryCacheExpireObject");
- ast_manager_unregister("SorceryMemoryCacheExpire");
- ast_manager_unregister("SorceryMemoryCacheStaleObject");
- ast_manager_unregister("SorceryMemoryCacheStale");
-
AST_TEST_UNREGISTER(open_with_valid_options);
AST_TEST_UNREGISTER(open_with_invalid_options);
AST_TEST_UNREGISTER(create_and_retrieve);
@@ -2505,6 +2489,27 @@ static int unload_module(void)
AST_TEST_UNREGISTER(expiration);
AST_TEST_UNREGISTER(stale);
+ ast_manager_unregister("SorceryMemoryCacheExpireObject");
+ ast_manager_unregister("SorceryMemoryCacheExpire");
+ ast_manager_unregister("SorceryMemoryCacheStaleObject");
+ ast_manager_unregister("SorceryMemoryCacheStale");
+
+ ast_cli_unregister_multiple(cli_memory_cache, ARRAY_LEN(cli_memory_cache));
+
+ ast_sorcery_wizard_unregister(&memory_cache_object_wizard);
+
+ /*
+ * XXX There is the potential to leak memory if there are pending
+ * next-cache-expiration and stale-cache-update tasks in the scheduler.
+ */
+ if (sched) {
+ ast_sched_context_destroy(sched);
+ sched = NULL;
+ }
+
+ ao2_cleanup(caches);
+ caches = NULL;
+
return 0;
}
@@ -2512,6 +2517,14 @@ static int load_module(void)
{
int res;
+ caches = ao2_container_alloc(CACHES_CONTAINER_BUCKET_SIZE, sorcery_memory_cache_hash,
+ sorcery_memory_cache_cmp);
+ if (!caches) {
+ ast_log(LOG_ERROR, "Failed to create container for configured caches\n");
+ unload_module();
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
sched = ast_sched_context_create();
if (!sched) {
ast_log(LOG_ERROR, "Failed to create scheduler for cache management\n");
@@ -2525,14 +2538,6 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
- caches = ao2_container_alloc(CACHES_CONTAINER_BUCKET_SIZE, sorcery_memory_cache_hash,
- sorcery_memory_cache_cmp);
- if (!caches) {
- ast_log(LOG_ERROR, "Failed to create container for configured caches\n");
- unload_module();
- return AST_MODULE_LOAD_DECLINE;
- }
-
if (ast_sorcery_wizard_register(&memory_cache_object_wizard)) {
unload_module();
return AST_MODULE_LOAD_DECLINE;