From: Patrick Lerda Date: Sat, 25 Mar 2023 01:14:32 +0000 (+0100) Subject: r600/sfn: fix memory leak related to sh_info->arrays X-Git-Tag: upstream/23.3.3~9697 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e45fa939b09049cc6d6a55d637ca0139633c76fc;p=platform%2Fupstream%2Fmesa.git r600/sfn: fix memory leak related to sh_info->arrays For instance, with "piglit/bin/shader_runner tests/spec/glsl-1.10/execution/glsl-vs-arrays-2.shader_test -auto -fbo": Direct leak of 12 byte(s) in 1 object(s) allocated from: #0 0x7f33c3f3d097 in operator new[](unsigned long) (/usr/lib64/libasan.so.6+0xb3097) #1 0x7f33b9af1e5b in r600::ValueFactory::get_shader_info(r600_shader*) ../src/gallium/drivers/r600/sfn/sfn_valuefactory.cpp:1056 #2 0x7f33b9a96860 in r600::Shader::get_shader_info(r600_shader*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:1445 #3 0x7f33b99ddd07 in r600_shader_from_nir ../src/gallium/drivers/r600/sfn/sfn_nir.cpp:1032 #4 0x7f33b9c3e701 in r600_pipe_shader_create ../src/gallium/drivers/r600/r600_shader.c:231 Fixes: 79ca456b4837 ("r600/sfn: rewrite NIR backend") Signed-off-by: Patrick Lerda Part-of: --- diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index ed51fa7..b8b8dc4 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -420,6 +420,9 @@ void r600_pipe_shader_destroy(struct pipe_context *ctx UNUSED, struct r600_pipe_ if (list_is_linked(&shader->shader.bc.cf)) r600_bytecode_clear(&shader->shader.bc); r600_release_command_buffer(&shader->command_buffer); + + if (shader->shader.arrays) + free(shader->shader.arrays); } /* diff --git a/src/gallium/drivers/r600/sfn/sfn_valuefactory.cpp b/src/gallium/drivers/r600/sfn/sfn_valuefactory.cpp index 3466300..e8088cf 100644 --- a/src/gallium/drivers/r600/sfn/sfn_valuefactory.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_valuefactory.cpp @@ -1053,7 +1053,8 @@ ValueFactory::get_shader_info(r600_shader *sh_info) if (!arrays.empty()) { sh_info->num_arrays = arrays.size(); - sh_info->arrays = new r600_shader_array[arrays.size()]; + sh_info->arrays = + (r600_shader_array *)malloc(sizeof(struct r600_shader_array) * arrays.size()); for (auto& arr : arrays) { sh_info->arrays->gpr_start = arr->sel();