summaryrefslogtreecommitdiff
path: root/glsl_types.cpp
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-06-18 17:52:59 -0700
committerCarl Worth <cworth@cworth.org>2010-06-23 19:00:42 -0700
commit12c411504ca86341f8b96c349c15413ee198cc71 (patch)
treeb6b00d8e7c8789b34d1e0f5686959dc95571b93f /glsl_types.cpp
parentdc5811fd0c7600b165ddd4e04a0ccae69bb19ec8 (diff)
Close memory leaks in glsl_type (constructor and get_array_instance)
Add a talloc ctx to both get_array_instance and the glsl_type constructor in order to be able to call talloc_size instead of malloc. This fix now makes glsl-orangebook-ch06-bump.frag 99.99% leak free: total heap usage: 55,623 allocs, 55,615 Only 8 missing frees now.
Diffstat (limited to 'glsl_types.cpp')
-rw-r--r--glsl_types.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/glsl_types.cpp b/glsl_types.cpp
index 7dcb4a4caf..d1b9dc6412 100644
--- a/glsl_types.cpp
+++ b/glsl_types.cpp
@@ -574,7 +574,7 @@ _mesa_glsl_initialize_constructors(exec_list *instructions,
}
-glsl_type::glsl_type(const glsl_type *array, unsigned length) :
+glsl_type::glsl_type(void *ctx, const glsl_type *array, unsigned length) :
base_type(GLSL_TYPE_ARRAY),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
sampler_type(0),
@@ -588,7 +588,7 @@ glsl_type::glsl_type(const glsl_type *array, unsigned length) :
* NUL.
*/
const unsigned name_length = strlen(array->name) + 10 + 3;
- char *const n = (char *) malloc(name_length);
+ char *const n = (char *) talloc_size(ctx, name_length);
if (length == 0)
snprintf(n, name_length, "%s[]", array->name);
@@ -691,9 +691,10 @@ glsl_type::array_key_hash(const void *a)
const glsl_type *
-glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
+glsl_type::get_array_instance(void *ctx, const glsl_type *base,
+ unsigned array_size)
{
- const glsl_type key(base, array_size);
+ const glsl_type key(ctx, base, array_size);
if (array_types == NULL) {
array_types = hash_table_ctor(64, array_key_hash, array_key_compare);
@@ -701,7 +702,7 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
const glsl_type *t = (glsl_type *) hash_table_find(array_types, & key);
if (t == NULL) {
- t = new glsl_type(base, array_size);
+ t = new glsl_type(ctx, base, array_size);
hash_table_insert(array_types, (void *) t, t);
}