]> git.ozlabs.org Git - petitboot/commitdiff
test/parser: cleanup parser allocations on exit
authorJeremy Kerr <jk@ozlabs.org>
Mon, 20 May 2013 02:28:23 +0000 (10:28 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 20 May 2013 02:28:23 +0000 (10:28 +0800)
We should talloc_free the parser list once we're done, enabling
valgrind's leak check. Before:

 [jk@pablo parser]$ valgrind ./test-null
 ...
 ==9330== HEAP SUMMARY:
 ==9330==     in use at exit: 288 bytes in 3 blocks
 ==9330==   total heap usage: 11 allocs, 8 frees, 1,177 bytes allocated

After:

 [jk@pablo parser]$ valgrind ./test-null
 ...
 ==9940== HEAP SUMMARY:
 ==9940==     in use at exit: 0 bytes in 0 blocks
 ==9940==   total heap usage: 11 allocs, 11 frees, 1,177 bytes allocated
 ==9940==
 ==9940== All heap blocks were freed -- no leaks are possible

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/parser/utils.c

index 9a6b2e145061969eabaf62a9d96ebc72823825df..6f78c2f93e36e8da2b117bd1ee94e64885e49fc2 100644 (file)
@@ -32,6 +32,14 @@ void __register_parser(struct parser *parser)
        list_add(&parsers, &i->list);
 }
 
        list_add(&parsers, &i->list);
 }
 
+static void __attribute__((destructor)) __cleanup_parsers(void)
+{
+       struct p_item *item, *tmp;
+
+       list_for_each_entry_safe(&parsers, item, tmp, list)
+               talloc_free(item);
+}
+
 static struct discover_device *test_create_device_simple(
                struct discover_context *ctx)
 {
 static struct discover_device *test_create_device_simple(
                struct discover_context *ctx)
 {