Mesa (master): glsl: Hook up loop_variable_state destructor to plug a memory leak.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Jun 7 07:01:15 UTC 2012


Module: Mesa
Branch: master
Commit: 3603fdcebfa25e2217f1dbfb0a99261be3e84b02
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3603fdcebfa25e2217f1dbfb0a99261be3e84b02

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Jun  5 15:58:41 2012 -0700

glsl: Hook up loop_variable_state destructor to plug a memory leak.

While ~loop_state() is already freeing the loop_variable_state objects
via ralloc_free(this->mem_ctx), the ~loop_variable_state() destructor
was never getting called, so the hash table inside loop_variable_state
was never getting destroyed.

Fixes a memory leak in any shader with loops.

NOTE: This is a candidate for stable release branches.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/loop_analysis.h |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/glsl/loop_analysis.h b/src/glsl/loop_analysis.h
index 8bed1db..05c982f 100644
--- a/src/glsl/loop_analysis.h
+++ b/src/glsl/loop_analysis.h
@@ -140,6 +140,23 @@ public:
    {
       hash_table_dtor(this->var_hash);
    }
+
+   static void* operator new(size_t size, void *ctx)
+   {
+      void *lvs = ralloc_size(ctx, size);
+      assert(lvs != NULL);
+
+      ralloc_set_destructor(lvs, (void (*)(void*)) destructor);
+
+      return lvs;
+   }
+
+private:
+   static void
+   destructor(loop_variable_state *lvs)
+   {
+      lvs->~loop_variable_state();
+   }
 };
 
 




More information about the mesa-commit mailing list