aboutsummaryrefslogtreecommitdiffstats
path: root/main/astobj2.c
diff options
context:
space:
mode:
authordvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-11 18:42:25 +0000
committerdvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-11 18:42:25 +0000
commit3d1363a494ba23d8bba3aa8a0001eb314ba9e4cc (patch)
tree1b846b2d9f4e5959d77c76a3d9d8c6812ce90dac /main/astobj2.c
parent1dea8c2fc19cdbbbbdbed3c9b1c94b5644d9a345 (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: http://svn.digium.com/svn/asterisk/trunk@246299 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/astobj2.c')
-rw-r--r--main/astobj2.c12
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