qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH][Outreachy] Signed-off-by: Sarah Khan <address@h


From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH][Outreachy] Signed-off-by: Sarah Khan <address@hidden>
Date: Fri, 4 Mar 2016 16:44:22 +0000

On 4 March 2016 at 16:35, Eric Blake <address@hidden> wrote:
> On 03/04/2016 09:06 AM, Peter Maydell wrote:
>
>>>> +++ b/thunk.c
>>>> @@ -88,7 +88,7 @@ void thunk_register_struct(int id, const char *name, 
>>>> const argtype *types)
>>>>      for(i = 0;i < 2; i++) {
>>>>          offset = 0;
>>>>          max_align = 1;
>>>> -        se->field_offsets[i] = malloc(nb_fields * sizeof(int));
>>>> +        se->field_offsets[i] = g_malloc(nb_fields * sizeof(int));
>>>>          type_ptr = se->field_types;
>>>>          for(j = 0;j < nb_fields; j++) {
>>>>              size = thunk_type_size(type_ptr, i);
>>>
>>> Where is the corresponding free()?  g_malloc() must be paired with
>>> g_free(), so you need to convert both places at once.
>>
>> There is no corresponding free(). thunk_register_struct() is called
>> only at startup from the linux-user code in order to populate the
>> struct_entries array; this data structure then remains live for
>> the entire lifetime of the program and is automatically freed when
>> QEMU exits.
>
> Fair enough.  However, g_new(int, nb_fields) is probably a bit nicer
> than g_malloc() (in that it would detect multiplication overflow if
> nb_fields were ever oversized).

Yes, good idea.

thanks
-- PMM



reply via email to

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