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 a9b5fda3764ab811c4002334d4538913c9c7ec28..33e17d73401cd141267b6ef7b5589782f1ffe336 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 231d91d59763c39c4edb4ec46f6d40b9db2d73e1..a675a1ac5abe7348759d38e016f47a66c03e70c4 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 60455d50f86d82577c5296a107b3cad536e7beb1..0ab81d4d714c7d694ad06437423e4d66b1127cae 100644 (file)
@@ -282,9 +282,23 @@ qir_compile_init(void)
         return c;
 }
 
+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 05a3249d39b0de017ad2cd85d70b694159cc7e5b..fbf56f02a3a0d760568694cb2eea0b32cad90d00 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);