Re: [PATCH v2] target/riscv: Fix memory leak in riscv_trigger_unrealize()

Alistair <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.nongnu.qemu-devel
Message-ID <[email protected]>
On Fri, 2026-07-24 at 14:39 +0800, Zeng Chi wrote:
> From: Zeng Chi <[email protected]>
> 
> In riscv_trigger_unrealize(), the per-trigger QEMUTimer objects are
> created in riscv_trigger_realize() using timer_new_ns().  However,
> unrealize only calls timer_del() to cancel them, but never frees the
> timer objects themselves. This results in a memory leak every time a
> CPU instance is unrealized (e.g., during hot-unplug or machine
> teardown).
> 
> Fix it by replacing timer_del() with timer_free(), which internally
> cancels the timer and frees its memory.  The separate timer_del()
> call
> is no longer needed.
> 
> Fixes: 820552a92e32 ("target/riscv: dynamic alloc of debug trigger
> arrays")
> Signed-off-by: Zeng Chi <[email protected]>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  target/riscv/tcg/debug.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/riscv/tcg/debug.c b/target/riscv/tcg/debug.c
> index 3c0fe70101..5ab29f6945 100644
> --- a/target/riscv/tcg/debug.c
> +++ b/target/riscv/tcg/debug.c
> @@ -1080,7 +1080,7 @@ void riscv_trigger_unrealize(CPURISCVState
> *env)
>      g_free(env->cpu_watchpoint);
>  
>      for (int i = 0; i < env->num_triggers; i++) {
> -        timer_del(env->itrigger_timer[i]);
> +        timer_free(env->itrigger_timer[i]);
>      }
>      g_free(env->itrigger_timer);
>  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.