From 66313732a7c1c3a64421ac7657b47f0eaf4d3bf9 Mon Sep 17 00:00:00 2001 From: Patrick Lerda Date: Fri, 3 Feb 2023 13:52:41 +0100 Subject: [PATCH] mesa/program: fix memory leak triggered by parser errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Marek Olšák Part-of: --- src/mesa/program/program_parse.y | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y index bef20f4e766..ba4757ff74e 100644 --- a/src/mesa/program/program_parse.y +++ b/src/mesa/program/program_parse.y @@ -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