qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Resource leaking in gen_intermediate_code_internal ?


From: Peter Maydell
Subject: Re: [Qemu-devel] Resource leaking in gen_intermediate_code_internal ?
Date: Tue, 30 Jun 2015 09:14:40 +0100

On 30 June 2015 at 03:45, Jun Koi <address@hidden> wrote:
> Hello,
>
> In function gen_intermediate_code_internal() of target-i386/translate.c, we
> have this code:
>
>     cpu_T[0] = tcg_temp_new();
>     cpu_T[1] = tcg_temp_new();
>     cpu_A0 = tcg_temp_new();
>
>
> I cannot see anywhere cpu_T & cpu_A0 are freed, so each time this function
> is called, it allocates new variables without freeing old variables. So we
> have resource leaking here?

TCG temporaries are effectively auto-freed at the end of each TB
(in fact there's no memory allocation going on -- there's a fixed
array of memory that's used by tcg.c for temp information, and at
the start of each TB it's initialized to "no temporaries in use").

It's important to free the temporaries that are created as we
generate an instruction, because otherwise the guest code could
make us run out of temps by repeating the instruction that leaked
a temp over and over. But a temp that's only allocated once at
the top of gen_intermediate_code_internal() is not going to
cause a resource leak.

(Personally I think creating a bunch of temps once and then
using them a lot while generating code is slightly bad style,
but the x86 translator is very old and has a lot of style
quirks that date back to before we had TCG at all.)

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]