aboutsummaryrefslogtreecommitdiffstats
path: root/main/astobj2.c
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-17 21:26:31 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-17 21:26:31 +0000
commitb92e2c0bd7d143aab5372dd1220df0989b6be517 (patch)
treefac0c3a4267b6f2829f923da0a7840d99b756a44 /main/astobj2.c
parent2be42b53afd9af37f25eae316936cc2f51630da4 (diff)
_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. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@123526 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/astobj2.c')
-rw-r--r--main/astobj2.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/main/astobj2.c b/main/astobj2.c
index e9e2db7e5..391154828 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -930,6 +930,12 @@ static char *handle_astobj2_test(struct ast_cli_entry *e, int cmd, struct ast_cl
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");