[asterisk-commits] kpfleming: trunk r225955 - /trunk/main/astobj2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 26 17:03:33 CDT 2009


Author: kpfleming
Date: Mon Oct 26 17:03:29 2009
New Revision: 225955

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=225955
Log:
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.

Modified:
    trunk/main/astobj2.c

Modified: trunk/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/astobj2.c?view=diff&rev=225955&r1=225954&r2=225955
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Mon Oct 26 17:03:29 2009
@@ -685,6 +685,7 @@
 				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 @@
 				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 @@
 				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 */
 			}
 




More information about the asterisk-commits mailing list