[Spice-devel] [spice-server PATCH 6/8] red_get_image_data_flat: allocate mem after sanity check

Uri Lublin uril at redhat.com
Wed Oct 26 15:28:55 UTC 2016


On 10/17/2016 01:11 PM, Frediano Ziglio wrote:
>>
>> This patch prevents possible memory leak.
>>
>> Found by coverity.
>>
>> Signed-off-by: Uri Lublin <uril at redhat.com>
>> ---
>>  server/red-parse-qxl.c | 11 +++++++----
>>  1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/server/red-parse-qxl.c b/server/red-parse-qxl.c
>> index d75e27e..4dcf4ee 100644
>> --- a/server/red-parse-qxl.c
>> +++ b/server/red-parse-qxl.c
>> @@ -371,13 +371,16 @@ static SpiceChunks
>> *red_get_image_data_flat(RedMemSlotInfo *slots, int group_id,
>>  {
>>      SpiceChunks *data;
>>      int error;
>> +    unsigned long bitmap_virt;
>> +
>
> This assumes LP64 architectures, why not using a

Hi Frediano,

I think no assumption is introduced by this patch.

memslot_get_virt returns unsigned long so that's the type
I used for bitmap_virt.

I do not think using void* makes it "safer".

Possibly we can change memslot_get_virt to remove the assumption.

Thanks,
     Uri.

>
>     void *image_data;
>
>> +    bitmap_virt = memslot_get_virt(slots, addr, size, group_id, &error);
>
> here
>
>     image_data = (void*)memslot_get_virt(slots, addr, size, group_id, &error);
>
>> +    if (error) {
>> +        return 0;
>> +    }
>>
>>      data = spice_chunks_new(1);
>>      data->data_size      = size;
>> -    data->chunk[0].data  = (void*)memslot_get_virt(slots, addr, size,
>> group_id, &error);
>> -    if (error) {
>> -        return 0;
>> -    }
>> +    data->chunk[0].data  = (void*)bitmap_virt;
>
> here
>
>     data->chunk[0].data  = image_data;
>
>>      data->chunk[0].len   = size;
>>      return data;
>>  }
>
> This is portable to LLP64 (I know, Linux is always LP64 but it does not
> cost much).
>
> Frediano
>



More information about the Spice-devel mailing list