ao2_iterator: Mini-audit of the ao2_iterator loops in the new code files.

* Fixed several places where ao2_iterator_destroy() was not called.

* Fixed several iterator loop object variable reference problems.

* Fixed res_parking AMI actions returning non-zero.  Only the AMI logoff
action can return non-zero.

Review: https://reviewboard.asterisk.org/r/3087/
........

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


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404436 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2013-12-20 20:00:50 +00:00
parent c2fd2ac823
commit 72c282cc66
8 changed files with 52 additions and 35 deletions

View File

@@ -682,6 +682,7 @@ void ast_ari_bridges_list(struct ast_variable *headers,
struct ast_json *json_bridge = ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer());
if (!json_bridge || ast_json_array_append(json, json_bridge)) {
ao2_iterator_destroy(&i);
ast_ari_response_alloc_failed(response);
return;
}

View File

@@ -663,8 +663,8 @@ void ast_ari_channels_list(struct ast_variable *headers,
return;
}
for (i = ao2_iterator_init(snapshots, 0);
(obj = ao2_iterator_next(&i)); ao2_cleanup(obj)) {
i = ao2_iterator_init(snapshots, 0);
while ((obj = ao2_iterator_next(&i))) {
RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup);
struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
int r;
@@ -678,7 +678,6 @@ void ast_ari_channels_list(struct ast_variable *headers,
json, ast_channel_snapshot_to_json(snapshot, NULL));
if (r != 0) {
ast_ari_response_alloc_failed(response);
ao2_cleanup(obj);
ao2_iterator_destroy(&i);
return;
}

View File

@@ -74,12 +74,14 @@ void ast_ari_endpoints_list(struct ast_variable *headers,
int r;
if (!json_endpoint) {
ao2_iterator_destroy(&i);
return;
}
r = ast_json_array_append(
json, json_endpoint);
if (r != 0) {
ao2_iterator_destroy(&i);
ast_ari_response_alloc_failed(response);
return;
}
@@ -144,6 +146,7 @@ void ast_ari_endpoints_list_by_tech(struct ast_variable *headers,
r = ast_json_array_append(
json, json_endpoint);
if (r != 0) {
ao2_iterator_destroy(&i);
ast_ari_response_alloc_failed(response);
return;
}

View File

@@ -229,7 +229,7 @@ static struct ast_str *manager_build_parked_call_string(const struct ast_parked_
return out;
}
static int manager_parking_status_single_lot(struct mansession *s, const struct message *m, const char *id_text, const char *lot_name)
static void manager_parking_status_single_lot(struct mansession *s, const struct message *m, const char *id_text, const char *lot_name)
{
RAII_VAR(struct parking_lot *, curlot, NULL, ao2_cleanup);
struct parked_user *curuser;
@@ -237,10 +237,9 @@ static int manager_parking_status_single_lot(struct mansession *s, const struct
int total = 0;
curlot = parking_lot_find_by_name(lot_name);
if (!curlot) {
astman_send_error(s, m, "Requested parking lot could not be found.");
return RESULT_SUCCESS;
return;
}
astman_send_ack(s, m, "Parked calls will follow");
@@ -252,14 +251,18 @@ static int manager_parking_status_single_lot(struct mansession *s, const struct
payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL);
if (!payload) {
ao2_ref(curuser, -1);
ao2_iterator_destroy(&iter_users);
astman_send_error(s, m, "Failed to retrieve parking data about a parked user.");
return RESULT_FAILURE;
return;
}
parked_call_string = manager_build_parked_call_string(payload);
if (!parked_call_string) {
astman_send_error(s, m, "Failed to retrieve parkingd ata about a parked user.");
return RESULT_FAILURE;
ao2_ref(curuser, -1);
ao2_iterator_destroy(&iter_users);
astman_send_error(s, m, "Failed to retrieve parking data about a parked user.");
return;
}
total++;
@@ -273,7 +276,6 @@ static int manager_parking_status_single_lot(struct mansession *s, const struct
ao2_ref(curuser, -1);
}
ao2_iterator_destroy(&iter_users);
astman_append(s,
@@ -282,11 +284,9 @@ static int manager_parking_status_single_lot(struct mansession *s, const struct
"%s"
"\r\n",
total, id_text);
return RESULT_SUCCESS;
}
static int manager_parking_status_all_lots(struct mansession *s, const struct message *m, const char *id_text)
static void manager_parking_status_all_lots(struct mansession *s, const struct message *m, const char *id_text)
{
struct parked_user *curuser;
struct ao2_container *lot_container;
@@ -296,17 +296,15 @@ static int manager_parking_status_all_lots(struct mansession *s, const struct me
int total = 0;
lot_container = get_parking_lot_container();
if (!lot_container) {
ast_log(LOG_ERROR, "Failed to obtain parking lot list. Action canceled.\n");
astman_send_error(s, m, "Could not create parking lot list");
return RESULT_SUCCESS;
return;
}
iter_lots = ao2_iterator_init(lot_container, 0);
astman_send_ack(s, m, "Parked calls will follow");
iter_lots = ao2_iterator_init(lot_container, 0);
while ((curlot = ao2_iterator_next(&iter_lots))) {
iter_users = ao2_iterator_init(curlot->parked_users, 0);
while ((curuser = ao2_iterator_next(&iter_users))) {
@@ -315,12 +313,20 @@ static int manager_parking_status_all_lots(struct mansession *s, const struct me
payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL);
if (!payload) {
return RESULT_FAILURE;
ao2_ref(curuser, -1);
ao2_iterator_destroy(&iter_users);
ao2_ref(curlot, -1);
ao2_iterator_destroy(&iter_lots);
return;
}
parked_call_string = manager_build_parked_call_string(payload);
if (!payload) {
return RESULT_FAILURE;
if (!parked_call_string) {
ao2_ref(curuser, -1);
ao2_iterator_destroy(&iter_users);
ao2_ref(curlot, -1);
ao2_iterator_destroy(&iter_lots);
return;
}
total++;
@@ -337,7 +343,6 @@ static int manager_parking_status_all_lots(struct mansession *s, const struct me
ao2_iterator_destroy(&iter_users);
ao2_ref(curlot, -1);
}
ao2_iterator_destroy(&iter_lots);
astman_append(s,
@@ -346,8 +351,6 @@ static int manager_parking_status_all_lots(struct mansession *s, const struct me
"%s"
"\r\n",
total, id_text);
return RESULT_SUCCESS;
}
static int manager_parking_status(struct mansession *s, const struct message *m)
@@ -361,11 +364,12 @@ static int manager_parking_status(struct mansession *s, const struct message *m)
}
if (!ast_strlen_zero(lot_name)) {
return manager_parking_status_single_lot(s, m, id_text, lot_name);
manager_parking_status_single_lot(s, m, id_text, lot_name);
} else {
manager_parking_status_all_lots(s, m, id_text);
}
return manager_parking_status_all_lots(s, m, id_text);
return 0;
}
static int manager_append_event_parking_lot_data_cb(void *obj, void *arg, void *data, int flags)
@@ -401,11 +405,10 @@ static int manager_parking_lot_list(struct mansession *s, const struct message *
}
lot_container = get_parking_lot_container();
if (!lot_container) {
ast_log(LOG_ERROR, "Failed to obtain parking lot list. Action canceled.\n");
astman_send_error(s, m, "Could not create parking lot list");
return -1;
return 0;
}
astman_send_ack(s, m, "Parking lots will follow");
@@ -417,7 +420,7 @@ static int manager_parking_lot_list(struct mansession *s, const struct message *
"%s"
"\r\n",id_text);
return RESULT_SUCCESS;
return 0;
}
static int manager_park(struct mansession *s, const struct message *m)

View File

@@ -304,6 +304,7 @@ int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
ao2_ref(contact, -1);
if (res) {
ao2_iterator_destroy(&i);
return -1;
}
}