]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Resolve some memory leaks due to incorrect for loop / ao2 ref usage.
authorMark Michelson <mmichelson@digium.com>
Fri, 18 Oct 2013 18:33:35 +0000 (18:33 +0000)
committerMark Michelson <mmichelson@digium.com>
Fri, 18 Oct 2013 18:33:35 +0000 (18:33 +0000)
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

main/bridge.c
main/bucket.c
main/cli.c
main/manager.c
main/sorcery.c

index a972fe7363148562680cd33709fdbba77da63a55..feeb564d4cd336d76636104beba4237351d6827f 100644 (file)
@@ -4533,6 +4533,7 @@ static char *complete_bridge_stasis(const char *word, int state)
 
                if (!strncasecmp(word, snapshot->uniqueid, wordlen) && (++which > state)) {
                        ret = ast_strdup(snapshot->uniqueid);
+                       ao2_ref(msg, -1);
                        break;
                }
        }
index 3ad47652827c63d8c80830901de56237137ee8ba..8f6acdaa5829fd0d29f0f7c13177c32d5f1cebce 100644 (file)
@@ -520,6 +520,7 @@ struct ast_json *ast_bucket_json(const struct ast_bucket *bucket)
 
                if (!bucket_uri || ast_json_array_append(buckets, bucket_uri)) {
                        res = -1;
+                       ao2_ref(uri, -1);
                        break;
                }
        }
@@ -544,6 +545,7 @@ struct ast_json *ast_bucket_json(const struct ast_bucket *bucket)
 
                if (!file_uri || ast_json_array_append(files, file_uri)) {
                        res = -1;
+                       ao2_ref(uri, -1);
                        break;
                }
        }
index 9d9fda4f1947b1f54e8d2ae22549c0da6d331996..a9f466499cd74420bee8a99b9094b3a866c81b1f 100644 (file)
@@ -1581,6 +1581,7 @@ char *ast_complete_channels(const char *line, const char *word, int pos, int sta
 
                if (!strncasecmp(word, snapshot->name, wordlen) && (++which > state)) {
                        ret = ast_strdup(snapshot->name);
+                       ao2_ref(msg, -1);
                        break;
                }
        }
index f3e883407fe9f6ee6cb62bff8c419ef95079a618..a531feb80008aa855ded733321da082c513a0d2a 100644 (file)
@@ -3932,6 +3932,7 @@ static int action_status(struct mansession *s, const struct message *m)
                ast_free(built);
 
                if (!all) {
+                       ao2_ref(msg, -1);
                        break;
                }
        }
index 3f2346dfeeed1c2de0472b2fb0a138d8ce8df912..3b58188dac993148ae00daeef6bfb8455b0ac06c 100644 (file)
@@ -927,6 +927,7 @@ struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sor
                        struct ast_variable *field;
 
                        if ((res = object_field->multiple_handler(object, &tmp))) {
+                               ao2_ref(object_field, -1);
                                break;
                        }