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 <[email protected]>

I'd prefer to see the 'autofree' used here but I'm also happy with your
patch as-is.

Acked-by: Tyler Hicks <[email protected]>

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
> <[email protected]>
> http://NxNW.org/~steve/



> -- 
> AppArmor mailing list
> [email protected]
> Modify settings or unsubscribe at: 
> https://lists.ubuntu.com/mailman/listinfo/apparmor

Attachment: signature.asc
Description: Digital signature

-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to