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
This commit is contained in:
David Vossel
2010-02-11 18:42:25 +00:00
parent 1321748c19
commit 9478670527
2 changed files with 387 additions and 4 deletions

View File

@@ -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