vc4: Fix memory leaks of some vc4_compile contents.
authorEric Anholt <eric@anholt.net>
Mon, 15 Sep 2014 19:15:02 +0000 (12:15 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 15 Sep 2014 20:12:27 +0000 (13:12 -0700)
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.c

index 01d4bad..12584e1 100644 (file)
@@ -28,6 +28,7 @@
 #include "util/u_hash_table.h"
 #include "util/u_hash.h"
 #include "util/u_memory.h"
+#include "util/ralloc.h"
 #include "tgsi/tgsi_dump.h"
 #include "tgsi/tgsi_info.h"
 
@@ -1312,14 +1313,14 @@ vc4_shader_tgsi_to_qir(struct vc4_compiled_shader *shader, enum qstage stage,
         c->stage = stage;
 
         /* XXX sizing */
-        c->temps = calloc(sizeof(struct qreg), 1024);
-        c->inputs = calloc(sizeof(struct qreg), 8 * 4);
-        c->outputs = calloc(sizeof(struct qreg), 1024);
-        c->uniforms = calloc(sizeof(struct qreg), 1024);
-        c->consts = calloc(sizeof(struct qreg), 1024);
+        c->temps = ralloc_array(c, struct qreg, 1024);
+        c->inputs = ralloc_array(c, struct qreg, 8 * 4);
+        c->outputs = ralloc_array(c, struct qreg, 1024);
+        c->uniforms = ralloc_array(c, struct qreg, 1024);
+        c->consts = ralloc_array(c, struct qreg, 1024);
 
-        c->uniform_data = calloc(sizeof(uint32_t), 1024);
-        c->uniform_contents = calloc(sizeof(enum quniform_contents), 1024);
+        c->uniform_data = ralloc_array(c, uint32_t, 1024);
+        c->uniform_contents = ralloc_array(c, enum quniform_contents, 1024);
 
         c->shader_state = key->shader_state;
         ret = tgsi_parse_init(&c->parser, c->shader_state->tokens);
@@ -1383,7 +1384,6 @@ vc4_shader_tgsi_to_qir(struct vc4_compiled_shader *shader, enum qstage stage,
         }
 
         tgsi_parse_free(&c->parser);
-        free(c->temps);
 
         qir_optimize(c);
 
index ef8a4e5..60455d5 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "util/u_memory.h"
 #include "util/u_simple_list.h"
+#include "util/ralloc.h"
 
 #include "vc4_qir.h"
 #include "vc4_qpu.h"
@@ -274,7 +275,7 @@ qir_reg_equals(struct qreg a, struct qreg b)
 struct vc4_compile *
 qir_compile_init(void)
 {
-        struct vc4_compile *c = CALLOC_STRUCT(vc4_compile);
+        struct vc4_compile *c = rzalloc(NULL, struct vc4_compile);
 
         make_empty_list(&c->instructions);
 
@@ -284,7 +285,7 @@ qir_compile_init(void)
 void
 qir_compile_destroy(struct vc4_compile *c)
 {
-        free(c);
+        ralloc_free(c);
 }
 
 const char *