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;
}
}
* \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.
* \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.
* \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.
* \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.
* \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.
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;
}
}
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;
}
"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;
}
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;
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);
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;
}
}
if (ast_json_object_set(json, "cause", failure_cause)) {
- ast_json_unref(failure_cause);
return;
}
}