[svn-commits] mmichelson: trunk r123526 - /trunk/main/astobj2.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 17 16:26:32 CDT 2008


Author: mmichelson
Date: Tue Jun 17 16:26:31 2008
New Revision: 123526

URL: http://svn.digium.com/view/asterisk?view=rev&rev=123526
Log:
_ys pointed out in #asterisk-bugs that he was experiencing
a memory leak when running the astobj2 test CLI command. After
searching, it appears the leak was in the command handler itself.

Each object was allocated (recount = 1) and then linked into
a container (refounct = 2). Then at the end of the function, 
the container was unreffed, causing all the objects to have
their refcount decremented by one, leaving the refcount for
all objects allocated in that function at 1. I've now added
an extra unref to the mix so that the refcount equals zero
when the container is unreffed.


Modified:
    trunk/main/astobj2.c

Modified: trunk/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/trunk/main/astobj2.c?view=diff&rev=123526&r1=123525&r2=123526
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Tue Jun 17 16:26:31 2008
@@ -930,6 +930,12 @@
 		ast_cli(a->fd, "object %d allocated as %p\n", i, obj);
 		sprintf(obj, "-- this is obj %d --", i);
 		ao2_link(c1, obj);
+		/* At this point, the refcount on obj is 2 due to the allocation
+		 * and linking. We can go ahead and reduce the refcount by 1
+		 * right here so that when the container is unreffed later, the
+		 * objects will be freed
+		 */
+		ao2_t_ref(obj, -1, test);
 	}
 	ast_cli(a->fd, "testing callbacks\n");
 	ao2_t_callback(c1, 0, print_cb, &a->fd,"test callback");




More information about the svn-commits mailing list