[apparmor] [parser] fix memory leaks in variable failure cases
Tyler Hicks
tyhicks at canonical.com
Mon Jan 25 22:27:31 UTC 2016
On 2016-01-25 13:17:04, Steve Beattie wrote:
> This patch frees some leaked variables that occur when errors are
> detected while adding variables to the parser's symbol table. While not
> a significant issue currently due to the parser exiting on failures, as
> the process of library-ifying the parser continues, these need to be
> addressed. It also makes it easier to use tools like Address Sanitizer
> on the parser against our test suite.
>
> Signed-off-by: Steve Beattie <steve at nxnw.org>
I'd prefer to see the 'autofree' used here but I'm also happy with your
patch as-is.
Acked-by: Tyler Hicks <tyhicks at canonical.com>
Tyler
> ---
> parser/parser_yacc.y | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> Index: b/parser/parser_yacc.y
> ===================================================================
> --- a/parser/parser_yacc.y
> +++ b/parser/parser_yacc.y
> @@ -419,14 +419,17 @@ varassign: TOK_SET_VAR TOK_EQUALS valuel
> PDEBUG("Matched: set assignment for (%s)\n", $1);
> err = new_set_var(var_name, list->value);
> if (err) {
> + free(var_name);
> yyerror("variable %s was previously declared", $1);
> /* FIXME: it'd be handy to report the previous location */
> }
> for (list = list->next; list; list = list->next) {
> err = add_set_value(var_name, list->value);
> - if (err)
> + if (err) {
> + free(var_name);
> yyerror("Error adding %s to set var %s",
> list->value, $1);
> + }
> }
> free_value_list($3);
> free(var_name);
> @@ -445,13 +448,16 @@ varassign: TOK_SET_VAR TOK_ADD_ASSIGN va
> * failures are indicative of symtab failures */
> err = add_set_value(var_name, list->value);
> if (err) {
> + free(var_name);
> yyerror("variable %s was not previously declared, but is being assigned additional values", $1);
> }
> for (list = list->next; list; list = list->next) {
> err = add_set_value(var_name, list->value);
> - if (err)
> + if (err) {
> + free(var_name);
> yyerror("Error adding %s to set var %s",
> list->value, $1);
> + }
> }
> free_value_list($3);
> free(var_name);
> @@ -469,11 +475,11 @@ varassign: TOK_BOOL_VAR TOK_EQUALS TOK_V
> $1, $3);
> }
> err = add_boolean_var(var_name, boolean);
> + free(var_name);
> if (err) {
> yyerror("variable %s was previously declared", $1);
> /* FIXME: it'd be handy to report the previous location */
> }
> - free(var_name);
> free($1);
> free($3);
> }
>
> --
> Steve Beattie
> <sbeattie at ubuntu.com>
> http://NxNW.org/~steve/
> --
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
-------------- 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/20160125/1b993335/attachment.pgp>
More information about the AppArmor
mailing list