From cd711b42596cb1727117656cdf4e4eb575a6c9dc Mon Sep 17 00:00:00 2001 From: Patrick Lerda Date: Fri, 12 Jan 2024 02:18:35 +0100 Subject: [PATCH] glsl/nir: fix gl_nir_cross_validate_outputs_to_inputs() memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For instance, this issue is triggered with vs-to-fs-overlap.shader_test -auto -fbo: Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7fe64f58e9a7 in calloc (/usr/lib64/libasan.so.6+0xb19a7) #1 0x7fe642ca2839 in _mesa_symbol_table_ctor ../src/mesa/program/symbol_table.c:286 #2 0x7fe642ff003d in gl_nir_cross_validate_outputs_to_inputs ../src/compiler/glsl/gl_nir_link_varyings.c:728 #3 0x7fe642d7c7d8 in gl_nir_link_glsl ../src/compiler/glsl/gl_nir_linker.c:1357 #4 0x7fe642be6931 in st_link_glsl_to_nir ../src/mesa/state_tracker/st_glsl_to_nir.cpp:562 #5 0x7fe642be6931 in st_link_shader ../src/mesa/state_tracker/st_glsl_to_nir.cpp:944 #6 0x7fe642acab55 in link_program ../src/mesa/main/shaderapi.c:1336 #7 0x7fe642acab55 in link_program_error ../src/mesa/main/shaderapi.c:1447 #8 0x7fe6424aa389 in _mesa_unmarshal_LinkProgram src/mapi/glapi/gen/marshal_generated2.c:1911 #9 0x7fe641fd912b in glthread_unmarshal_batch ../src/mesa/main/glthread.c:139 #10 0x7fe641f48d48 in util_queue_thread_func ../src/util/u_queue.c:309 #11 0x7fe641fa442a in impl_thrd_routine ../src/c11/impl/threads_posix.c:67 Fixes: 7d1948e9b5d9 ("glsl: implement cross_validate_outputs_to_inputs() in nir linker") Signed-off-by: Patrick Lerda Reviewed-by: Marek Olšák Part-of: (cherry picked from commit bacace8634346f853547f51a0ea6ff8082a8dcb8) --- .pick_status.json | 2 +- src/compiler/glsl/gl_nir_link_varyings.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 49bb2593cd1..9e837040ed0 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -84,7 +84,7 @@ "description": "glsl/nir: fix gl_nir_cross_validate_outputs_to_inputs() memory leak", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "7d1948e9b5d953cf8f5a56c676c935621b8da2bd", "notes": null diff --git a/src/compiler/glsl/gl_nir_link_varyings.c b/src/compiler/glsl/gl_nir_link_varyings.c index e3ba6fb2812..707c30392c4 100644 --- a/src/compiler/glsl/gl_nir_link_varyings.c +++ b/src/compiler/glsl/gl_nir_link_varyings.c @@ -746,7 +746,7 @@ gl_nir_cross_validate_outputs_to_inputs(const struct gl_constants *consts, if (!validate_explicit_variable_location(consts, output_explicit_locations, var, prog, producer)) { - return; + goto out; } } } @@ -800,7 +800,7 @@ gl_nir_cross_validate_outputs_to_inputs(const struct gl_constants *consts, if (!validate_explicit_variable_location(consts, input_explicit_locations, input, prog, consumer)) { - return; + goto out; } while (idx < slot_limit) { @@ -808,7 +808,7 @@ gl_nir_cross_validate_outputs_to_inputs(const struct gl_constants *consts, linker_error(prog, "Invalid location %u in %s shader\n", idx, _mesa_shader_stage_to_string(consumer->Stage)); - return; + goto out; } output = output_explicit_locations[idx][input->data.location_frac].var; @@ -871,6 +871,7 @@ gl_nir_cross_validate_outputs_to_inputs(const struct gl_constants *consts, } } + out: _mesa_symbol_table_dtor(table); }