[apparmor] [patch 09/13] parser - fix more memory leaks

John Johansen john.johansen at canonical.com
Mon Oct 14 08:33:28 UTC 2013


On 10/10/2013 01:46 PM, Steve Beattie wrote:
> This patch fixes a few more parser memory leaks as identified by the
> simple valgrind test script. These mostly occur during cleanup of
> structs and classes and as such, don't represent very serious leaks
> for common usages of the parser.
> 
> Signed-off-by: Steve Beattie <steve at nxnw.org>
Acked-by: John Johansen <john.johansen at canonical.com>

> ---
>  parser/parser_lex.l  |    8 +++++---
>  parser/parser_misc.c |    5 +++++
>  parser/profile.cc    |    7 ++++++-
>  3 files changed, 16 insertions(+), 4 deletions(-)
> 
> Index: b/parser/parser_misc.c
> ===================================================================
> --- a/parser/parser_misc.c
> +++ b/parser/parser_misc.c
> @@ -2,6 +2,9 @@
>   *   Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
>   *   NOVELL (All rights reserved)
>   *
> + *   Copyright (c) 2013
> + *   Canonical Ltd. (All rights reserved)
> + *
>   *   This program is free software; you can redistribute it and/or
>   *   modify it under the terms of version 2 of the GNU General Public
>   *   License published by the Free Software Foundation.
> @@ -874,6 +877,8 @@ void free_cod_entries(struct cod_entry *
>  		free(list->name);
>  	if (list->link_name)
>  		free(list->link_name);
> +	if (list->nt_name)
> +		free(list->nt_name);
>  	if (list->pat.regex)
>  		free(list->pat.regex);
>  	free(list);
> Index: b/parser/profile.cc
> ===================================================================
> --- a/parser/profile.cc
> +++ b/parser/profile.cc
> @@ -1,5 +1,5 @@
>  /*
> - *   Copyright (c) 2012
> + *   Copyright (c) 2012, 2013
>   *   Canonical, Ltd. (All rights reserved)
>   *
>   *   This program is free software; you can redistribute it and/or
> @@ -72,12 +72,17 @@ Profile::~Profile()
>  		aare_delete_ruleset(policy.rules);
>  	if (policy.dfa)
>  		free(policy.dfa);
> +	if (xmatch)
> +		free(xmatch);
>  	if (name)
>  		free(name);
>  	if (attachment)
>  		free(attachment);
>  	if (ns)
>  		free(ns);
> +	for (int i = (AA_EXEC_LOCAL >> 10) + 1; i < AA_EXEC_COUNT; i++)
> +		if (exec_table[i])
> +			free(exec_table[i]);
>  	if (net.allow)
>  		free(net.allow);
>  	if (net.audit)
> Index: b/parser/parser_lex.l
> ===================================================================
> --- a/parser/parser_lex.l
> +++ b/parser/parser_lex.l
> @@ -1,8 +1,8 @@
>  /*
>   *   Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
>   *   NOVELL (All rights reserved)
> - *   Copyright (c) 2010 - 2012
> - *   Canonical Ltd.
> + *   Copyright (c) 2010 - 2013
> + *   Canonical Ltd. (All rights reserved)
>   *
>   *   This program is free software; you can redistribute it and/or
>   *   modify it under the terms of version 2 of the GNU General Public
> @@ -167,8 +167,10 @@ static int include_dir_cb(__unused DIR *
>  	if (asprintf(&path, "%s/%s", d->fullpath, name) < 0)
>  		yyerror("Out of memory");
>  
> -	if (is_blacklisted(name, path))
> +	if (is_blacklisted(name, path)) {
> +		free(path);
>  		return 0;
> +	}
>  
>  	if (S_ISREG(st->st_mode)) {
>  		if (!(yyin = fopen(path,"r")))
> 
> 
> -- AppArmor mailing list AppArmor at lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
> 




More information about the AppArmor mailing list