[Mesa-dev] [PATCH 1/6] mesa/st/tests: Fix zero-byte allocation leaks

Gert Wollny gw.fossdev at gmail.com
Wed Oct 4 09:45:25 UTC 2017


Don't allocate a zero-sized array, when no texture offsets are given.
---
 .../tests/test_glsl_to_tgsi_lifetime.cpp           | 23 +++++++++++++++-------
 1 file changed, 16 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 93f4020ebf..d0ac8b1020 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,10 +1411,15 @@ 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);
    }
    ++num_temps;
-- 
2.13.6



More information about the mesa-dev mailing list