[Asterisk-code-review] Dialplan functions: Fix some channel autoservice misuse. (asterisk[13])

Jenkins2 asteriskteam at digium.com
Wed Jun 20 16:37:00 CDT 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/9206 )

Change subject: Dialplan functions: Fix some channel autoservice misuse.
......................................................................

Dialplan functions: Fix some channel autoservice misuse.

* Fix off nominal paths leaving the channel in autoservice.
* Remove unnecessary start/stop channel autoservice.
* Fix channel locking around a channel datastore search.

Change-Id: I7ff2e42388064fe3149034ecae57604040b8b540
---
M funcs/func_curl.c
M funcs/func_realtime.c
M main/enum.c
3 files changed, 23 insertions(+), 19 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index b1bb759..89a4688 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -636,14 +636,14 @@
 		return -1;
 	}
 
-	if (chan) {
-		ast_autoservice_start(chan);
-	}
-
 	if (!(curl = ast_threadstorage_get(&curl_instance, sizeof(*curl)))) {
 		ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
 		ast_free(str);
 		return -1;
+	}
+
+	if (chan) {
+		ast_autoservice_start(chan);
 	}
 
 	AST_LIST_LOCK(&global_curl_info);
@@ -656,14 +656,19 @@
 	}
 	AST_LIST_UNLOCK(&global_curl_info);
 
-	if (chan && (store = ast_channel_datastore_find(chan, &curl_info, NULL))) {
-		list = store->data;
-		AST_LIST_LOCK(list);
-		AST_LIST_TRAVERSE(list, cur, list) {
-			if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
-				hashcompat = (long) cur->value;
-			} else {
-				curl_easy_setopt(*curl, cur->key, cur->value);
+	if (chan) {
+		ast_channel_lock(chan);
+		store = ast_channel_datastore_find(chan, &curl_info, NULL);
+		ast_channel_unlock(chan);
+		if (store) {
+			list = store->data;
+			AST_LIST_LOCK(list);
+			AST_LIST_TRAVERSE(list, cur, list) {
+				if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
+					hashcompat = (long) cur->value;
+				} else {
+					curl_easy_setopt(*curl, cur->key, cur->value);
+				}
 			}
 		}
 	}
diff --git a/funcs/func_realtime.c b/funcs/func_realtime.c
index a870ab4..2fc4df8 100644
--- a/funcs/func_realtime.c
+++ b/funcs/func_realtime.c
@@ -227,6 +227,9 @@
 
 	if (resultslen > len) {
 		ast_log(LOG_WARNING, "Failed to fetch. Realtime data is too large: need %zu, have %zu.\n", resultslen, len);
+		if (chan) {
+			ast_autoservice_stop(chan);
+		}
 		return -1;
 	}
 
@@ -460,6 +463,9 @@
 			 * someones data without giving him the chance to look
 			 * at it. */
 			ast_log(LOG_WARNING, "Failed to fetch/destroy. Realtime data is too large: need %zu, have %zu.\n", resultslen, len);
+			if (chan) {
+				ast_autoservice_stop(chan);
+			}
 			return -1;
 		}
 
diff --git a/main/enum.c b/main/enum.c
index bae1299..e003f07 100644
--- a/main/enum.c
+++ b/main/enum.c
@@ -942,10 +942,6 @@
 
 	ast_debug(4, "ast_get_txt: Number = '%s', suffix = '%s'\n", number, suffix);
 
-	if (chan && ast_autoservice_start(chan) < 0) {
-		return -1;
-	}
-
 	if (pos > 128) {
 		pos = 128;
 	}
@@ -965,9 +961,6 @@
 		ret = 0;
 	} else {
 		ast_copy_string(txt, context.txt, txtlen);
-	}
-	if (chan) {
-		ret |= ast_autoservice_stop(chan);
 	}
 	return ret;
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I7ff2e42388064fe3149034ecae57604040b8b540
Gerrit-Change-Number: 9206
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180620/939737ea/attachment.html>


More information about the asterisk-code-review mailing list