]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix reference and container leaks when running 'astobj2 test.'
authorSean Bright <sean@malleable.com>
Wed, 15 Dec 2010 21:28:29 +0000 (21:28 +0000)
committerSean Bright <sean@malleable.com>
Wed, 15 Dec 2010 21:28:29 +0000 (21:28 +0000)
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

index 12da832d6482654d9ca9025ce2ea9b09a19f04f5..9a78a4c17ed5cd598c5e333eff632465d64fd40d 100644 (file)
@@ -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);