From a3ccbf2e594a34fc10c83f246cc21b19f35c8817 Mon Sep 17 00:00:00 2001 From: relapids Date: Mon, 15 Aug 2022 15:56:25 -0700 Subject: [PATCH] Fix memory leak in PPC target. --- qemu/target/ppc/unicorn.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qemu/target/ppc/unicorn.c b/qemu/target/ppc/unicorn.c index de91d88cdf..8ce3e02b05 100644 --- a/qemu/target/ppc/unicorn.c +++ b/qemu/target/ppc/unicorn.c @@ -109,6 +109,7 @@ static void ppc_release(void *ctx) int i; TCGContext *tcg_ctx = (TCGContext *)ctx; PowerPCCPU *cpu = (PowerPCCPU *)tcg_ctx->uc->cpu; + CPUPPCState *env = &cpu->env; CPUTLBDesc *d = cpu->neg.tlb.d; CPUTLBDescFast *f = cpu->neg.tlb.f; CPUTLBDesc *desc; @@ -132,6 +133,20 @@ static void ppc_release(void *ctx) // g_free(tcg_ctx->tb_ctx.tbs); + if (env->nb_tlb != 0) { + switch(env->tlb_type) { + case TLB_6XX: + g_free(env->tlb.tlb6); + break; + case TLB_EMB: + g_free(env->tlb.tlbe); + break; + case TLB_MAS: + g_free(env->tlb.tlbm); + break; + } + } + ppc_cpu_instance_finalize(tcg_ctx->uc->cpu); ppc_cpu_unrealize(tcg_ctx->uc->cpu); }