vc4: Fix memory leaks of struct qinst.
authorEric Anholt <eric@anholt.net>
Mon, 15 Sep 2014 19:19:28 +0000 (12:19 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 15 Sep 2014 20:12:27 +0000 (13:12 -0700)
src/gallium/drivers/vc4/vc4_opt_cse.c
src/gallium/drivers/vc4/vc4_opt_dead_code.c
src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h

index a9b5fda..33e17d7 100644 (file)
@@ -147,7 +147,7 @@ qir_opt_cse(struct vc4_compile *c)
                                         qir_dump_inst(inst);
                                         fprintf(stderr, "\n");
                                 }
-                                remove_from_list(&inst->link);
+                                qir_remove_instruction(inst);
                                 progress = true;
                                 continue;
                         } else {
index 231d91d..a675a1a 100644 (file)
@@ -54,8 +54,7 @@ qir_opt_dead_code(struct vc4_compile *c)
                                 qir_dump_inst(inst);
                                 fprintf(stderr, "\n");
                         }
-                        remove_from_list(&inst->link);
-                        free(inst);
+                        qir_remove_instruction(inst);
                         progress = true;
                         continue;
                 }
index 60455d5..0ab81d4 100644 (file)
@@ -283,8 +283,22 @@ qir_compile_init(void)
 }
 
 void
+qir_remove_instruction(struct qinst *qinst)
+{
+        remove_from_list(&qinst->link);
+        free(qinst->src);
+        free(qinst);
+}
+
+void
 qir_compile_destroy(struct vc4_compile *c)
 {
+        while (!is_empty_list(&c->instructions)) {
+                struct qinst *qinst =
+                        (struct qinst *)first_elem(&c->instructions);
+                qir_remove_instruction(qinst);
+        }
+
         ralloc_free(c);
 }
 
index 05a3249..fbf56f0 100644 (file)
@@ -245,6 +245,7 @@ struct qinst *qir_inst4(enum qop op, struct qreg dst,
                         struct qreg b,
                         struct qreg c,
                         struct qreg d);
+void qir_remove_instruction(struct qinst *qinst);
 void qir_emit(struct vc4_compile *c, struct qinst *inst);
 struct qreg qir_get_temp(struct vc4_compile *c);
 int qir_get_op_nsrc(enum qop qop);