diff options
author | Gert Wollny <[email protected]> | 2017-09-14 12:49:07 +0200 |
---|---|---|
committer | Brian Paul <[email protected]> | 2018-01-24 10:23:00 -0700 |
commit | ad1990629e4d855101977f39319db47f51daf536 (patch) | |
tree | 6ba52a9a58b2aa6fccbe513be8189e6c001a95e3 /src/mesa | |
parent | ee48e3acb87e2752b511a4915391c325f9b2c75d (diff) |
mesa/st/tests: Fix zero-byte allocation leaks
Don't allocate a zero-sized array, when no texture offsets are given.
v5: correct spaces and empty lines
Reviewed-by: Brian Paul <[email protected]>(v4)
Reviewed-by: Nicolai Hähnle <[email protected]> (v1)
Signed-off-by: Gert Wollny <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp | 22 |
1 files 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 93f4020ebf4..1c8b9acfa4f 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<MockCodelineWithSwizzle>& 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<MockCodeline>& 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); } |