[svn-commits] rmudgett: trunk r408714 - in /trunk: ./ apps/ include/asterisk/ main/ res/ re...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 21 12:04:57 CST 2014


Author: rmudgett
Date: Fri Feb 21 12:04:54 2014
New Revision: 408714

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408714
Log:
json: Fix off-nominal json ref counting issues.

* Fixed off-nominal json ref counting issue with using the following API
calls: ast_json_object_set() and ast_json_array_append().

* Fixed off-nominal error reporting in ast_ari_endpoints_list().

* Fixed some miscellaneous off-nominal json ref counting issues in
report_receive_fax_status() and dial_to_json().
........

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

Modified:
    trunk/   (props changed)
    trunk/apps/app_meetme.c
    trunk/include/asterisk/json.h
    trunk/main/sorcery.c
    trunk/main/stasis_channels.c
    trunk/res/ari/resource_endpoints.c
    trunk/res/res_fax.c
    trunk/res/res_sorcery_astdb.c
    trunk/res/res_stasis_recording.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_meetme.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/apps/app_meetme.c (original)
+++ trunk/apps/app_meetme.c Fri Feb 21 12:04:54 2014
@@ -1362,25 +1362,20 @@
 	if (user) {
 		struct timeval now = ast_tvnow();
 		long duration = (long)(now.tv_sec - user->jointime);
-		RAII_VAR(struct ast_json *, json_user, ast_json_integer_create(user->user_no), ast_json_unref);
-		RAII_VAR(struct ast_json *, json_user_duration, NULL, ast_json_unref);
-
-		if (ast_json_object_set(json_object, "user", json_user)) {
+		struct ast_json *json_user;
+		struct ast_json *json_user_duration;
+
+		json_user = ast_json_integer_create(user->user_no);
+		if (!json_user || ast_json_object_set(json_object, "user", json_user)) {
 			return;
 		}
-		json_user = NULL;
 
 		if (duration > 0) {
 			json_user_duration = ast_json_integer_create(duration);
-
-			if (!json_user_duration) {
+			if (!json_user_duration
+				|| ast_json_object_set(json_object, "duration", json_user_duration)) {
 				return;
 			}
-
-			if (ast_json_object_set(json_object, "duration", json_user_duration)) {
-				return;
-			}
-			json_user_duration = NULL;
 		}
 	}
 

Modified: trunk/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/json.h?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/include/asterisk/json.h (original)
+++ trunk/include/asterisk/json.h Fri Feb 21 12:04:54 2014
@@ -443,8 +443,8 @@
  * \brief Change an element in an array.
  * \since 12.0.0
  *
- * The \a array steals the \a value reference; use ast_json_ref() to safely keep a pointer
- * to it.
+ * \note The \a array steals the \a value reference even if it returns error;
+ * use ast_json_ref() to safely keep a pointer to it.
  *
  * \param array JSON array to modify.
  * \param index Zero-based index into array.
@@ -458,8 +458,8 @@
  * \brief Append to an array.
  * \since 12.0.0
  *
- * The array steals the \a value reference; use ast_json_ref() to safely keep a pointer
- * to it.
+ * \note The \a array steals the \a value reference even if it returns error;
+ * use ast_json_ref() to safely keep a pointer to it.
  *
  * \param array JSON array to modify.
  * \param value New JSON value to store at the end of \a array.
@@ -472,8 +472,8 @@
  * \brief Insert into an array.
  * \since 12.0.0
  *
- * The array steals the \a value reference; use ast_json_ref() to safely keep a pointer
- * to it.
+ * \note The \a array steals the \a value reference even if it returns error;
+ * use ast_json_ref() to safely keep a pointer to it.
  *
  * \param array JSON array to modify.
  * \param index Zero-based index into array.
@@ -554,8 +554,8 @@
  * \brief Set a field in a JSON object.
  * \since 12.0.0
  *
- * The object steals the \a value reference; use ast_json_ref() to safely keep a pointer
- * to it.
+ * \note The object steals the \a value reference even if it returns error;
+ * use ast_json_ref() to safely keep a pointer to it.
  *
  * \param object JSON object to modify.
  * \param key Key of field to set.
@@ -701,8 +701,8 @@
  * \brief Set the value of the field pointed to by an iterator.
  * \since 12.0.0
  *
- * The array steals the value reference; use ast_json_ref() to safely keep a
- * pointer to it.
+ * \note The object steals the \a value reference even if it returns error;
+ * use ast_json_ref() to safely keep a pointer to it.
  *
  * \param object JSON object \a iter was obtained from.
  * \param iter JSON object iterator.

Modified: trunk/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/sorcery.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/main/sorcery.c (original)
+++ trunk/main/sorcery.c Fri Feb 21 12:04:54 2014
@@ -1095,8 +1095,7 @@
 			for (field = tmp; field; field = field->next) {
 				struct ast_json *value = ast_json_string_create(field->value);
 
-				if (value && ast_json_object_set(json, field->name, value)) {
-					ast_json_unref(value);
+				if (!value || ast_json_object_set(json, field->name, value)) {
 					res = -1;
 				}
 			}
@@ -1106,10 +1105,9 @@
 			char *buf = NULL;
 			struct ast_json *value = NULL;
 
-			if ((res = object_field->handler(object, object_field->args, &buf)) ||
-				!(value = ast_json_string_create(buf)) ||
-				ast_json_object_set(json, object_field->name, value)) {
-				ast_json_unref(value);
+			if ((res = object_field->handler(object, object_field->args, &buf))
+				|| !(value = ast_json_string_create(buf))
+				|| ast_json_object_set(json, object_field->name, value)) {
 				res = -1;
 			}
 

Modified: trunk/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis_channels.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/main/stasis_channels.c (original)
+++ trunk/main/stasis_channels.c Fri Feb 21 12:04:54 2014
@@ -977,6 +977,9 @@
 		"forward", ast_json_object_get(blob, "forward"),
 		"dialstring", ast_json_object_get(blob, "dialstring"));
 	if (!json) {
+		ast_json_unref(caller_json);
+		ast_json_unref(peer_json);
+		ast_json_unref(forwarded_json);
 		return NULL;
 	}
 

Modified: trunk/res/ari/resource_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/resource_endpoints.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/res/ari/resource_endpoints.c (original)
+++ trunk/res/ari/resource_endpoints.c Fri Feb 21 12:04:54 2014
@@ -71,16 +71,8 @@
 		RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup);
 		struct ast_endpoint_snapshot *snapshot = stasis_message_data(msg);
 		struct ast_json *json_endpoint = ast_endpoint_snapshot_to_json(snapshot, stasis_app_get_sanitizer());
-		int r;
 
-		if (!json_endpoint) {
-			ao2_iterator_destroy(&i);
-			return;
-		}
-
-		r = ast_json_array_append(
-			json, json_endpoint);
-		if (r != 0) {
+		if (!json_endpoint || ast_json_array_append(json, json_endpoint)) {
 			ao2_iterator_destroy(&i);
 			ast_ari_response_alloc_failed(response);
 			return;

Modified: trunk/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_fax.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/res/res_fax.c (original)
+++ trunk/res/res_fax.c Fri Feb 21 12:04:54 2014
@@ -1774,6 +1774,7 @@
 	struct ast_json *json_filename = ast_json_string_create(filename);
 
 	if (!json_array || !json_filename) {
+		ast_json_unref(json_filename);
 		return -1;
 	}
 	ast_json_array_append(json_array, json_filename);

Modified: trunk/res/res_sorcery_astdb.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_sorcery_astdb.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/res/res_sorcery_astdb.c (original)
+++ trunk/res/res_sorcery_astdb.c Fri Feb 21 12:04:54 2014
@@ -76,7 +76,6 @@
 			ast_json_unref(json);
 			return NULL;
 		} else if (ast_json_object_set(json, field->name, value)) {
-			ast_json_unref(value);
 			ast_json_unref(json);
 			return NULL;
 		}

Modified: trunk/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_recording.c?view=diff&rev=408714&r1=408713&r2=408714
==============================================================================
--- trunk/res/res_stasis_recording.c (original)
+++ trunk/res/res_stasis_recording.c Fri Feb 21 12:04:54 2014
@@ -229,7 +229,6 @@
 		}
 
 		if (ast_json_object_set(json, "cause", failure_cause)) {
-			ast_json_unref(failure_cause);
 			return;
 		}
 	}




More information about the svn-commits mailing list