diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 4651bf0ebaf81121db81b4a2a34632779c4abb1e..37053b3e6702bfadc6b78e0c4304859a74928e3d 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -1362,25 +1362,20 @@ static void meetme_stasis_generate_msg(struct ast_conference *meetme_conference,
 	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);
+		struct ast_json *json_user;
+		struct ast_json *json_user_duration;
 
-		if (ast_json_object_set(json_object, "user", json_user)) {
+		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) {
-				return;
-			}
-
-			if (ast_json_object_set(json_object, "duration", json_user_duration)) {
+			if (!json_user_duration
+				|| ast_json_object_set(json_object, "duration", json_user_duration)) {
 				return;
 			}
-			json_user_duration = NULL;
 		}
 	}
 
diff --git a/include/asterisk/json.h b/include/asterisk/json.h
index 15e1108da653d9fc59294204a87a687f7c6239e0..6ceeb0b86fe63d1a04181af1a67985939318480e 100644
--- a/include/asterisk/json.h
+++ b/include/asterisk/json.h
@@ -443,8 +443,8 @@ struct ast_json *ast_json_array_get(const struct ast_json *array, size_t index);
  * \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 @@ int ast_json_array_set(struct ast_json *array, size_t index, struct ast_json *va
  * \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 @@ int ast_json_array_append(struct ast_json *array, struct ast_json *value);
  * \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 @@ struct ast_json *ast_json_object_get(struct ast_json *object, const char *key);
  * \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 @@ struct ast_json *ast_json_object_iter_value(struct ast_json_iter *iter);
  * \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.
diff --git a/main/sorcery.c b/main/sorcery.c
index 5104e3ada9a985817ca30de179d80271775a4ade..bbdfa8cf2bf4569eca3ac3574a7319e2bc80e966 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -1095,8 +1095,7 @@ struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sor
 			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 @@ struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sor
 			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;
 			}
 
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index 677527ba32f7a8b7565cc3bf26db62fe99647b9d..fe65c1766a5495958141cc69042681a810157b3d 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -977,6 +977,9 @@ static struct ast_json *dial_to_json(
 		"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;
 	}
 
diff --git a/res/ari/resource_endpoints.c b/res/ari/resource_endpoints.c
index 2f47b1a1a036b1a45d018919bcc428f7e7230c28..16b7ebd8d23e9c8bce0b80cc7e472b011356649f 100644
--- a/res/ari/resource_endpoints.c
+++ b/res/ari/resource_endpoints.c
@@ -71,16 +71,8 @@ void ast_ari_endpoints_list(struct ast_variable *headers,
 		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;
diff --git a/res/res_fax.c b/res/res_fax.c
index c4e64cd7176a6875a9862ae6454819aa6649c58b..e05b101f747ed25e2efc698808916cc67ecd1496 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -1774,6 +1774,7 @@ static int report_receive_fax_status(struct ast_channel *chan, const char *filen
 	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);
diff --git a/res/res_sorcery_astdb.c b/res/res_sorcery_astdb.c
index 10d881e8fb3f1e3eec543a1a7ae375199b0167ec..d04153ea25160f6073ffd6993c8943a43858b2aa 100644
--- a/res/res_sorcery_astdb.c
+++ b/res/res_sorcery_astdb.c
@@ -76,7 +76,6 @@ static struct ast_json *sorcery_objectset_to_json(const struct ast_variable *obj
 			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;
 		}
diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c
index f0fa1e5f6fdb71c7e1817ec535f85ab1e9bf6ef2..0dee1e5be7e610061eb4a40bcf13c386917c4edd 100644
--- a/res/res_stasis_recording.c
+++ b/res/res_stasis_recording.c
@@ -229,7 +229,6 @@ static void recording_publish(struct stasis_app_recording *recording, const char
 		}
 
 		if (ast_json_object_set(json, "cause", failure_cause)) {
-			ast_json_unref(failure_cause);
 			return;
 		}
 	}