[apparmor] Memory leaks in parser/parser_regex.c (at least)

Steve Beattie steve at nxnw.org
Thu Aug 27 20:44:58 UTC 2015


On Thu, Aug 27, 2015 at 10:35:11AM -0700, Steve Beattie wrote:
> The stuff I'm seeing is from running make check on the parser from the
> tip of the trunk in bzr, and getting failures in the caching tests like
> so:
> 
> ======================================================================
> FAIL: test_profile_newer_skips_cache (__main__.AAParserAltCacheTests)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/home/steve/bzr/apparmor/parser/tst/testlib.py", line 50, in new_unittest_func
>     return unittest_func(self)
>   File "./caching.py", line 384, in test_profile_newer_skips_cache
>     self._generate_cache_file()
>   File "./caching.py", line 233, in _generate_cache_file
>     self.run_cmd_check(cmd)
>   File "/home/steve/bzr/apparmor/parser/tst/testlib.py", line 73, in run_cmd_check
>     self.assertEqual(rc, expected_rc, "Got return code %d, expected %d\nCommand run: %s\nOutput: %s" % (rc, expected_rc, (' %'.join(command)), report))
> AssertionError: 23 != 0 : Got return code 23, expected 0
> Command run: ../apparmor_parser --base /home/steve/tmp/aa-caching-z8l3_5xj --skip-kernel-load --cache-loc /home/steve/tmp/aa-caching-z8l3_5xj/aa-alt-cachexyu9sztn -q --write-cache -r /home/steve/tmp/aa-caching-z8l3_5xj/sbin.pingy
> Output:
> =================================================================
> ==14259==ERROR: LeakSanitizer: detected memory leaks
> 
> Direct leak of 32 byte(s) in 1 object(s) allocated from:
>     #0 0x7f61775ecb49 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b49)
>     #1 0x4bb679 in aa_policy_cache_new /home/steve/bzr/apparmor/libraries/libapparmor/src/policy_cache.c:151
>     #2 0x41e968 in main /home/steve/bzr/apparmor/parser/parser_main.c:921
>     #3 0x7f6176c84a3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20a3f)
> 
> SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
> 
> 
> ----------------------------------------------------------------------

It looks like the parser never drops it's reference to the policy cache
object. This patch looks to fix the issue:

Signed-off-by: Steve Beattie <steve at nxnw.org>
---
 parser/parser_main.c |    1 +
 1 file changed, 1 insertion(+)

Index: b/parser/parser_main.c
===================================================================
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -992,6 +992,7 @@ int main(int argc, char *argv[])
 
 	if (ofile)
 		fclose(ofile);
+	aa_policy_cache_unref(policy_cache);
 
 	return last_error;
 }

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20150827/7e46b9b2/attachment.pgp>


More information about the AppArmor mailing list