diff options
author | David Vossel <dvossel@digium.com> | 2010-02-11 18:42:25 +0000 |
---|---|---|
committer | David Vossel <dvossel@digium.com> | 2010-02-11 18:42:25 +0000 |
commit | 9478670527b70107724dcb2cf01dc3e5d09c1803 (patch) | |
tree | 1b846b2d9f4e5959d77c76a3d9d8c6812ce90dac /main | |
parent | 1321748c19228e051a8db1dd497f10e1d6e55e20 (diff) |
astobj2 unit test and bug fix
A bug was discovered during the creation of the astobj2 unit test.
When OBJ_MULTIPLE | OBJ_UNLINK is used, the objects being returned
had a ref count issue. This patch resolves that.
Review: https://reviewboard.asterisk.org/r/496/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@246299 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/astobj2.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/main/astobj2.c b/main/astobj2.c index c119a28f8..48fae0a9d 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -724,10 +724,14 @@ static void *internal_ao2_callback(struct ao2_container *c, AST_LIST_REMOVE_CURRENT(entry); /* update number of elements */ ast_atomic_fetchadd_int(&c->elements, -1); - /* if the object is not going to be returned, we must decrement the reference count - * to account for the reference the container was holding - */ - if (flags & OBJ_NODATA) { + + /* - When unlinking and not returning the result, (OBJ_NODATA), the ref from the container + * must be decremented. + * - When unlinking with OBJ_MULTIPLE the ref from the original container + * must be decremented regardless if OBJ_NODATA is used. This is because the result is + * returned in a new container that already holds its own ref for the object. If the ref + * from the original container is not accounted for here a memory leak occurs. */ + if (flags & (OBJ_NODATA | OBJ_MULTIPLE)) { if (tag) __ao2_ref_debug(EXTERNAL_OBJ(cur->astobj), -1, tag, file, line, funcname); else |