On 30 June 2015 at 03:45, Jun Koi <[email protected]> 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