[asterisk-commits] Fix potential crash after unload of func periodic hook or te... (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 20 15:23:05 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: Fix potential crash after unload of func_periodic_hook or test_message.
......................................................................


Fix potential crash after unload of func_periodic_hook or test_message.

These modules save a pointer to the context they create on load, and
use that pointer to destroy the context at unload.  It is not safe
to save this pointer, it is replaced during load of pbx_config,
pbx_lua or pbx_ael.

This change causes the modules to pass NULL to ast_context_destroy,
a safer way to perform the unregistration since it does not use
a pointer that could become invalid.

ASTERISK-25085 #close
Reported by: Corey Farrell

Change-Id: I6a00ec8e38046058f97dc703e1adcde9bf517835
---
M funcs/func_periodic_hook.c
M tests/test_message.c
2 files changed, 4 insertions(+), 15 deletions(-)

Approvals:
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c
index 6ddab56..bb0ee0d 100644
--- a/funcs/func_periodic_hook.c
+++ b/funcs/func_periodic_hook.c
@@ -446,13 +446,9 @@
 	.write = hook_write,
 };
 
-static struct ast_context *func_periodic_hook_context;
-
 static int unload_module(void)
 {
-	if (func_periodic_hook_context) {
-		ast_context_destroy(func_periodic_hook_context, AST_MODULE);
-	}
+	ast_context_destroy(NULL, AST_MODULE);
 
 	return ast_custom_function_unregister(&hook_function);
 }
@@ -461,9 +457,7 @@
 {
 	int res;
 
-	func_periodic_hook_context = ast_context_find_or_create(NULL, NULL,
-			context_name, AST_MODULE);
-	if (!func_periodic_hook_context) {
+	if (!ast_context_find_or_create(NULL, NULL, context_name, AST_MODULE)) {
 		ast_log(LOG_ERROR, "Failed to create %s dialplan context.\n", context_name);
 		return AST_MODULE_LOAD_DECLINE;
 	}
diff --git a/tests/test_message.c b/tests/test_message.c
index 26cd90a..2c9334a 100644
--- a/tests/test_message.c
+++ b/tests/test_message.c
@@ -51,8 +51,6 @@
 /*! \brief The number of user events we should get in a dialplan test */
 #define DEFAULT_EXPECTED_EVENTS 4
 
-static struct ast_context *test_message_context;
-
 /*! \brief The current number of received user events */
 static int received_user_events;
 
@@ -822,9 +820,7 @@
 	AST_TEST_UNREGISTER(test_message_has_destination_handler);
 	AST_TEST_UNREGISTER(test_message_msg_send);
 
-	if (test_message_context) {
-		ast_context_destroy(test_message_context, AST_MODULE);
-	}
+	ast_context_destroy(NULL, AST_MODULE);
 
 	ast_manager_unregister_hook(&user_event_hook);
 
@@ -835,8 +831,7 @@
 {
 	int res = 0;
 
-	test_message_context = ast_context_find_or_create(NULL, NULL, TEST_CONTEXT, AST_MODULE);
-	if (!test_message_context) {
+	if (!ast_context_find_or_create(NULL, NULL, TEST_CONTEXT, AST_MODULE)) {
 		return -1;
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/468
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6a00ec8e38046058f97dc703e1adcde9bf517835
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list