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: 79ca456b48 ("r600/sfn: rewrite NIR backend")
Signed-off-by: Patrick Lerda <patrick9876@free.fr>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22262>
(cherry picked from commit e45fa939b0)
This commit is contained in:
Patrick Lerda 2023-03-25 02:14:32 +01:00 committed by Eric Engestrom
parent 49eb067746
commit 0b47ece7ae
3 changed files with 6 additions and 2 deletions

View file

@ -373,7 +373,7 @@
"description": "r600/sfn: fix memory leak related to sh_info->arrays",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "79ca456b4837b3bc21cf9ef3c03c505c4b4909f6"
},

View file

@ -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);
}
/*

View file

@ -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();