From d644f402d0b5baaf6e032f3954a00e5751235266 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Wed, 15 Dec 2010 21:28:29 +0000 Subject: [PATCH] Fix reference and container leaks when running 'astobj2 test.' We need to make sure that ao2_iterator_destroy is called once for each time that ao2_iterator_init is called. Also make sure to unref a newly allocated object that we've linked into a container. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@298345 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/astobj2.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main/astobj2.c b/main/astobj2.c index 12da832d64..9a78a4c17e 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -789,6 +789,7 @@ static int handle_astobj2_test(int fd, int argc, char *argv[]) ast_cli(fd, "object %d allocated as %p\n", i, obj); sprintf(obj, "-- this is obj %d --", i); ao2_link(c1, obj); + ao2_ref(obj, -1); } ast_cli(fd, "testing callbacks\n"); ao2_callback(c1, 0, print_cb, &fd); @@ -805,12 +806,14 @@ static int handle_astobj2_test(int fd, int argc, char *argv[]) ao2_unlink(c1, obj); ao2_ref(obj, -1); } + ao2_iterator_destroy(&ai); ast_cli(fd, "testing iterators again\n"); ai = ao2_iterator_init(c1, 0); while ( (obj = ao2_iterator_next(&ai)) ) { ast_cli(fd, "iterator on <%s>\n", obj); ao2_ref(obj, -1); } + ao2_iterator_destroy(&ai); } ast_cli(fd, "testing callbacks again\n"); ao2_callback(c1, 0, print_cb, &fd); -- 2.47.2