[asterisk-commits] res ari.c: Add missing off nominal unlock and remove a RAII ... (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 19 08:42:19 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: res_ari.c: Add missing off nominal unlock and remove a RAII_VAR().
......................................................................


res_ari.c: Add missing off nominal unlock and remove a RAII_VAR().

Change-Id: I0c5e7b34057f26dadb39489c4dac3015c52f5dbf
---
M res/res_ari.c
1 file changed, 11 insertions(+), 8 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Ashley Sanders: Looks good to me, but someone else must approve



diff --git a/res/res_ari.c b/res/res_ari.c
index 761c2dd..f39db16 100644
--- a/res/res_ari.c
+++ b/res/res_ari.c
@@ -180,8 +180,7 @@
 
 	SCOPED_MUTEX(lock, &root_handler_lock);
 
-	old_size = sizeof(*new_handler) +
-		root_handler->num_children * sizeof(handler);
+	old_size = sizeof(*new_handler) + root_handler->num_children * sizeof(handler);
 	new_size = old_size + sizeof(handler);
 
 	new_handler = ao2_alloc(new_size, NULL);
@@ -200,21 +199,24 @@
 
 int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
 {
-	RAII_VAR(struct stasis_rest_handlers *, new_handler, NULL, ao2_cleanup);
-	size_t size, i, j;
+	struct stasis_rest_handlers *new_handler;
+	size_t size;
+	size_t i;
+	size_t j;
 
 	ast_assert(root_handler != NULL);
 
 	ast_mutex_lock(&root_handler_lock);
-	size = sizeof(*new_handler) +
-		root_handler->num_children * sizeof(handler);
+	size = sizeof(*new_handler) + root_handler->num_children * sizeof(handler);
 
 	new_handler = ao2_alloc(size, NULL);
 	if (!new_handler) {
+		ast_mutex_unlock(&root_handler_lock);
 		return -1;
 	}
-	memcpy(new_handler, root_handler, sizeof(*new_handler));
 
+	/* Create replacement root_handler less the handler to remove. */
+	memcpy(new_handler, root_handler, sizeof(*new_handler));
 	for (i = 0, j = 0; i < root_handler->num_children; ++i) {
 		if (root_handler->children[i] == handler) {
 			ast_module_unref(ast_module_info->self);
@@ -224,9 +226,10 @@
 	}
 	new_handler->num_children = j;
 
+	/* Replace the old root_handler with the new. */
 	ao2_cleanup(root_handler);
-	ao2_ref(new_handler, +1);
 	root_handler = new_handler;
+
 	ast_mutex_unlock(&root_handler_lock);
 	return 0;
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0c5e7b34057f26dadb39489c4dac3015c52f5dbf
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Ashley Sanders <asanders at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list