From 2147dd96813d1faee5c55e84b332355ad05f070a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 15 Sep 2014 12:19:28 -0700 Subject: [PATCH] vc4: Fix memory leaks of struct qinst. --- src/gallium/drivers/vc4/vc4_opt_cse.c | 2 +- src/gallium/drivers/vc4/vc4_opt_dead_code.c | 3 +-- src/gallium/drivers/vc4/vc4_qir.c | 14 ++++++++++++++ src/gallium/drivers/vc4/vc4_qir.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/vc4/vc4_opt_cse.c b/src/gallium/drivers/vc4/vc4_opt_cse.c index a9b5fda3764..33e17d73401 100644 --- a/src/gallium/drivers/vc4/vc4_opt_cse.c +++ b/src/gallium/drivers/vc4/vc4_opt_cse.c @@ -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 { diff --git a/src/gallium/drivers/vc4/vc4_opt_dead_code.c b/src/gallium/drivers/vc4/vc4_opt_dead_code.c index 231d91d5976..a675a1ac5ab 100644 --- a/src/gallium/drivers/vc4/vc4_opt_dead_code.c +++ b/src/gallium/drivers/vc4/vc4_opt_dead_code.c @@ -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; } diff --git a/src/gallium/drivers/vc4/vc4_qir.c b/src/gallium/drivers/vc4/vc4_qir.c index 60455d50f86..0ab81d4d714 100644 --- a/src/gallium/drivers/vc4/vc4_qir.c +++ b/src/gallium/drivers/vc4/vc4_qir.c @@ -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); } diff --git a/src/gallium/drivers/vc4/vc4_qir.h b/src/gallium/drivers/vc4/vc4_qir.h index 05a3249d39b..fbf56f02a3a 100644 --- a/src/gallium/drivers/vc4/vc4_qir.h +++ b/src/gallium/drivers/vc4/vc4_qir.h @@ -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); -- 2.30.2