qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 2/2] qemu-img: free memory before re-assign


From: Pan Nengyuan
Subject: Re: [PATCH 2/2] qemu-img: free memory before re-assign
Date: Wed, 26 Feb 2020 18:32:41 +0800
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

On 2/26/2020 6:13 PM, Max Reitz wrote:
> On 26.02.20 04:30, Pan Nengyuan wrote:
>> collect_image_check() is called twice in img_check(), the filename/format 
>> will be alloced without free the original memory.
>> It is not a big deal since the process will exit anyway, but seems like a 
>> clean code and it will remove the warning spotted by asan.
>>
>> Reported-by: Euler Robot <address@hidden>
>> Signed-off-by: Pan Nengyuan <address@hidden>
>> ---
>>  qemu-img.c | 2 ++
>>  1 file changed, 2 insertions(+)
> 
> I think this should happen in the caller.  And there I think it would
> make more sense to completely discard the old object and allocate a new one:
> 
> qapi_free_ImageCheck(check);
> check = g_new0(ImageCheck, 1);
> 
> This way, we can’t forget to free any fields if new pointers were to be
> added to the ImageCheck object.

Good idea, thanks.

> 
> Max
> 



reply via email to

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