perf expr: Fix memory leaks in metric bison
Ian Rogers
reviewerPATCH 1/1 perf expr: Fix memory leaks in metric bison
Add a destructor for strings to reclaim memory in the event of errors. Free the ID given for a lookup, it was previously strdup-ed in the lex code.
Reviewed-by Andi Kleen <[email protected]>
Signed-off-by Ian Rogers <[email protected]>
--- tools/perf/util/expr.y | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/expr.y +3 -0
@@ -27,6 +27,7 @@ %token EXPR_PARSE EXPR_OTHER EXPR_ERROR %token <num> NUMBER %token <str> ID +%destructor { free ($$); } <str> %token MIN MAX IF ELSE SMT_ON %left MIN MAX IF %left '|'
@@ -94,8 +95,10 @@ if_expr: expr: NUMBER | ID { if (lookup_id(ctx, $1, &$$) < 0) { pr_debug("%s not found\n", $1); + free($1); YYABORT; } + free($1); } | expr '|' expr { $$ = (long)$1 | (long)$3; } | expr '&' expr { $$ = (long)$1 & (long)$3; }
Signature · 1 line
2.26.2.645.ge9eca65c58-goog
Quoted 6 lines · Ian Rogers
Add a destructor for strings to reclaim memory in the event of errors. Free the ID given for a lookup, it was previously strdup-ed in the lex code.
Reviewed-by Andi Kleen <[email protected]>Signed-off-by Ian Rogers <[email protected]>
Acked-by Jiri Olsa <[email protected]>
thanks,
jirka
Quoted 30 lines
--- tools/perf/util/expr.y | 3 +++ 1 file changed, 3 insertions(+)tools/perf/util/expr.y +3
-0@@ -27,6 +27,7 @@ %token EXPR_PARSE EXPR_OTHER EXPR_ERROR %token <num> NUMBER %token <str> ID +%destructor { free ($$); } <str> %token MIN MAX IF ELSE SMT_ON %left MIN MAX IF %left '|'@@ -94,8 +95,10 @@ if_expr: expr: NUMBER | ID { if (lookup_id(ctx, $1, &$$) < 0) { pr_debug("%s not found\n", $1); + free($1); YYABORT; } + free($1); } | expr '|' expr { $$ = (long)$1 | (long)$3; } | expr '&' expr { $$ = (long)$1 & (long)$3; }Signature · 1 line
2.26.2.645.ge9eca65c58-goog
Arnaldo Carvalho de Melo
AppliedEm Wed, May 13, 2020 at 07:52:53PM +0200, Jiri Olsa escreveu:
Quoted 9 lines · Ian Rogers
Quoted 6 lines
Add a destructor for strings to reclaim memory in the event of errors. Free the ID given for a lookup, it was previously strdup-ed in the lex code.
Reviewed-by Andi Kleen <[email protected]>Signed-off-by Ian Rogers <[email protected]>Acked-by Jiri Olsa <[email protected]>
Thanks, applied.
- Arnaldo