From ad1990629e4d855101977f39319db47f51daf536 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Thu, 14 Sep 2017 12:49:07 +0200 Subject: [PATCH] mesa/st/tests: Fix zero-byte allocation leaks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Don't allocate a zero-sized array, when no texture offsets are given. v5: correct spaces and empty lines Reviewed-by: Brian Paul (v4) Reviewed-by: Nicolai Hähnle (v1) Signed-off-by: Gert Wollny --- .../tests/test_glsl_to_tgsi_lifetime.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp index 93f4020..1c8b9ac 100644 --- a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp +++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp @@ -1374,10 +1374,14 @@ MockShader::MockShader(const vector& source): next_instr->dst[k] = create_dst_register(i.dst[k].first, i.dst[k].second); } next_instr->tex_offset_num_offset = i.tex_offsets.size(); - next_instr->tex_offsets = new st_src_reg[i.tex_offsets.size()]; - for (unsigned k = 0; k < i.tex_offsets.size(); ++k) { - next_instr->tex_offsets[k] = create_src_register(i.tex_offsets[k].first, - i.tex_offsets[k].second); + if (next_instr->tex_offset_num_offset > 0) { + next_instr->tex_offsets = new st_src_reg[i.tex_offsets.size()]; + for (unsigned k = 0; k < i.tex_offsets.size(); ++k) { + next_instr->tex_offsets[k] = create_src_register(i.tex_offsets[k].first, + i.tex_offsets[k].second); + } + } else { + next_instr->tex_offsets = nullptr; } program->push_tail(next_instr); } @@ -1407,9 +1411,13 @@ MockShader::MockShader(const vector& source): next_instr->dst[k] = create_dst_register(i.dst[k]); } next_instr->tex_offset_num_offset = i.tex_offsets.size(); - next_instr->tex_offsets = new st_src_reg[i.tex_offsets.size()]; - for (unsigned k = 0; k < i.tex_offsets.size(); ++k) { - next_instr->tex_offsets[k] = create_src_register(i.tex_offsets[k]); + if (next_instr->tex_offset_num_offset > 0) { + next_instr->tex_offsets = new st_src_reg[i.tex_offsets.size()]; + for (unsigned k = 0; k < i.tex_offsets.size(); ++k) { + next_instr->tex_offsets[k] = create_src_register(i.tex_offsets[k]); + } + } else { + next_instr->tex_offsets = nullptr; } program->push_tail(next_instr); } -- 2.7.4