A common idiom in Asterisk is to due something like:
for (ao2_obj = list_beginning; ao2_obj = next_item; ao2_ref(ao2_obj, -1)) {
...do stuff...
}
This is nice because it automatically takes care of the object references
for you. However, there is a pitfall here. If a break statement is in the
for loop, then the current reference is not cleaned up. In some cases, this
is on purpose, but in others there is a leak. This commit fixes the leak
cases.
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@401248
65c4cc65-6c06-0410-ace0-
fbb531ad65f3
if (!strncasecmp(word, snapshot->uniqueid, wordlen) && (++which > state)) {
ret = ast_strdup(snapshot->uniqueid);
+ ao2_ref(msg, -1);
break;
}
}
if (!bucket_uri || ast_json_array_append(buckets, bucket_uri)) {
res = -1;
+ ao2_ref(uri, -1);
break;
}
}
if (!file_uri || ast_json_array_append(files, file_uri)) {
res = -1;
+ ao2_ref(uri, -1);
break;
}
}
if (!strncasecmp(word, snapshot->name, wordlen) && (++which > state)) {
ret = ast_strdup(snapshot->name);
+ ao2_ref(msg, -1);
break;
}
}
ast_free(built);
if (!all) {
+ ao2_ref(msg, -1);
break;
}
}
struct ast_variable *field;
if ((res = object_field->multiple_handler(object, &tmp))) {
+ ao2_ref(object_field, -1);
break;
}