aboutsummaryrefslogtreecommitdiffstats
path: root/main/astobj2.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-10-26 22:03:29 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-10-26 22:03:29 +0000
commitef0206e9f1c3f9314a071517fd444937dee50579 (patch)
tree7987492ad578d888280a142374d57a013120256c /main/astobj2.c
parent24886e89c927322e173ce48e59fcc9f514856b4f (diff)
Correct broken logic from revision 225405.
The code committed in revision 225405 was broken; instead of removing the unreference code, the logic used to decide when to do it should have been reversed. This patch corrects the situation, and makes reference counting work properly again. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@225955 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/astobj2.c')
-rw-r--r--main/astobj2.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/main/astobj2.c b/main/astobj2.c
index da52ab1f0..a7dd7cc25 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -685,6 +685,7 @@ static void *internal_ao2_callback(struct ao2_container *c,
match &= cb_default(EXTERNAL_OBJ(cur->astobj), arg, flags);
}
+ /* we found the object, performing operations according flags */
if (match == 0) { /* no match, no stop, continue */
continue;
} else if (match == CMP_STOP) { /* no match but stop, we are done */
@@ -692,7 +693,6 @@ static void *internal_ao2_callback(struct ao2_container *c,
break;
}
- /* we found the object, performing operations according flags */
/* we have a match (CMP_MATCH) here */
if (!(flags & OBJ_NODATA)) { /* if must return the object, record the value */
/* it is important to handle this case before the unlink */
@@ -719,6 +719,15 @@ 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) {
+ if (tag)
+ __ao2_ref_debug(EXTERNAL_OBJ(cur->astobj), -1, tag, file, line, funcname);
+ else
+ __ao2_ref(EXTERNAL_OBJ(cur->astobj), -1);
+ }
ast_free(cur); /* free the link record */
}