From c30170d9a22255e35606a8c506e398f817a5c15c Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Fri, 18 Oct 2013 18:44:21 +0000 Subject: Resolve some memory leaks due to incorrect for loop / ao2 ref usage. 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. ........ Merged revisions 401248 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@401249 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/bridge.c | 1 + main/bucket.c | 2 ++ main/cli.c | 1 + main/manager.c | 1 + main/sorcery.c | 1 + 5 files changed, 6 insertions(+) diff --git a/main/bridge.c b/main/bridge.c index a972fe736..feeb564d4 100644 --- a/main/bridge.c +++ b/main/bridge.c @@ -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; } } diff --git a/main/bucket.c b/main/bucket.c index 3ad476528..8f6acdaa5 100644 --- a/main/bucket.c +++ b/main/bucket.c @@ -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; } } diff --git a/main/cli.c b/main/cli.c index 9d9fda4f1..a9f466499 100644 --- a/main/cli.c +++ b/main/cli.c @@ -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; } } diff --git a/main/manager.c b/main/manager.c index f3e883407..a531feb80 100644 --- a/main/manager.c +++ b/main/manager.c @@ -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; } } diff --git a/main/sorcery.c b/main/sorcery.c index 3f2346dfe..3b58188da 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -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; } -- cgit v1.2.3