Skip to content

Commit

Permalink
mesa/program: fix memory leak triggered by parser errors
Browse files Browse the repository at this point in the history
This change requires the %destructor directive which is supported
by bison or yacc, yacc needs to be compiled with the back-tracking
functionality.

This issue could be checked with the following piglit programs:
glsl-invalid-asm-01, glsl-invalid-asm-02 or vp-bad-program

Direct leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x7f8dc89050 in __interceptor_strdup (/usr/lib64/libasan.so.6+0x59050)
    #1 0x7f83791cbc in handle_ident ../src/mesa/program/program_lexer.l:129
    #2 0x7f83791cbc in _mesa_program_lexer_lex ../src/mesa/program/program_lexer.l:312
    #3 0x7f8377e8d8 in yylex ../src/mesa/program/program_parse.y:289
    #4 0x7f8377e8d8 in yyparse src/mesa/program/program_parse.tab.c:2124
    #5 0x7f83788c14 in _mesa_parse_arb_program ../src/mesa/program/program_parse.y:2584
    #6 0x7f8377371c in _mesa_parse_arb_fragment_program ../src/mesa/program/arbprogparse.c:82
    #7 0x7f8372d42c in set_program_string ../src/mesa/main/arbprogram.c:402

Signed-off-by: Patrick Lerda <[email protected]>
Acked-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21150>
  • Loading branch information
Patrick Lerda authored and Marge Bot committed Feb 8, 2023
1 parent 3061ec3 commit 6631373
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/mesa/program/program_parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ yylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
}
%}

/* The directive: %destructor is called to clean up the stack
* after a parser error.
*/
%destructor { free($$); } IDENTIFIER USED_IDENTIFIER

%%

program: language optionSequence statementSequence END
Expand Down

0 comments on commit 6631373

Please sign in to comment.