mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 16:21:01 +00:00
sorcery.c: Fix off-nominal path ref and memory leak in ast_sorcery_objectset_json_create().
* Made exit a loop early on error in ast_sorcery_objectset_json_create(). * Removed some dead code in ast_sorcery_objectset_create2(). ........ Merged revisions 410089 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410092 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1056,8 +1056,8 @@ struct ast_variable *ast_sorcery_objectset_create2(const struct ast_sorcery *sor
|
|||||||
RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->object->type, OBJ_KEY), ao2_cleanup);
|
RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->object->type, OBJ_KEY), ao2_cleanup);
|
||||||
struct ao2_iterator i;
|
struct ao2_iterator i;
|
||||||
struct ast_sorcery_object_field *object_field;
|
struct ast_sorcery_object_field *object_field;
|
||||||
struct ast_variable *head = NULL, *tail = NULL;
|
struct ast_variable *head = NULL;
|
||||||
int res = 0;
|
struct ast_variable *tail = NULL;
|
||||||
|
|
||||||
if (!object_type) {
|
if (!object_type) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1065,8 +1065,8 @@ struct ast_variable *ast_sorcery_objectset_create2(const struct ast_sorcery *sor
|
|||||||
|
|
||||||
i = ao2_iterator_init(object_type->fields, 0);
|
i = ao2_iterator_init(object_type->fields, 0);
|
||||||
|
|
||||||
for (; (object_field = ao2_iterator_next(&i)) && !res; ao2_ref(object_field, -1)) {
|
for (; (object_field = ao2_iterator_next(&i)); ao2_ref(object_field, -1)) {
|
||||||
struct ast_variable *tmp = NULL;
|
struct ast_variable *tmp;
|
||||||
|
|
||||||
switch (flags) {
|
switch (flags) {
|
||||||
case AST_HANDLER_PREFER_LIST:
|
case AST_HANDLER_PREFER_LIST:
|
||||||
@@ -1096,17 +1096,10 @@ struct ast_variable *ast_sorcery_objectset_create2(const struct ast_sorcery *sor
|
|||||||
}
|
}
|
||||||
|
|
||||||
tail = ast_variable_list_append_hint(&head, tail, tmp);
|
tail = ast_variable_list_append_hint(&head, tail, tmp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ao2_iterator_destroy(&i);
|
ao2_iterator_destroy(&i);
|
||||||
|
|
||||||
/* If any error occurs we destroy all fields handled before so a partial objectset is not returned */
|
|
||||||
if (res) {
|
|
||||||
ast_variables_destroy(head);
|
|
||||||
head = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1125,12 +1118,13 @@ struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sor
|
|||||||
|
|
||||||
i = ao2_iterator_init(object_type->fields, 0);
|
i = ao2_iterator_init(object_type->fields, 0);
|
||||||
|
|
||||||
for (; (object_field = ao2_iterator_next(&i)) && !res; ao2_ref(object_field, -1)) {
|
for (; !res && (object_field = ao2_iterator_next(&i)); ao2_ref(object_field, -1)) {
|
||||||
if (object_field->multiple_handler) {
|
if (object_field->multiple_handler) {
|
||||||
struct ast_variable *tmp = NULL;
|
struct ast_variable *tmp = NULL;
|
||||||
struct ast_variable *field;
|
struct ast_variable *field;
|
||||||
|
|
||||||
if ((res = object_field->multiple_handler(object, &tmp))) {
|
if ((res = object_field->multiple_handler(object, &tmp))) {
|
||||||
|
ast_variables_destroy(tmp);
|
||||||
ao2_ref(object_field, -1);
|
ao2_ref(object_field, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1140,6 +1134,7 @@ struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sor
|
|||||||
|
|
||||||
if (!value || ast_json_object_set(json, field->name, value)) {
|
if (!value || ast_json_object_set(json, field->name, value)) {
|
||||||
res = -1;
|
res = -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user