qemu-trivial
[Top][All Lists]
Advanced

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH] oslib-posix: change free to g_fr


From: Gonglei
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] oslib-posix: change free to g_free
Date: Sat, 11 Oct 2014 11:21:07 +0800
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1

On 2014/10/11 11:10, Zhanghailiang wrote:

> On 2014/10/11 10:54, address@hidden wrote:
>> From: Gonglei <address@hidden>
>>
>> The caller of qemu_vfree() maybe not check whether parameter
>> ptr pointer is NULL or not, such as vpc_open().
>> Using g_free() is more safe.
>>
> 
> It seems that free(NULL) is harmless.
> 

Actually, I had noted that C standard says it is a no-operation.
But that doesn't mean that every C-library handles it like that.
Some people saw crashes for free(NULL), so it's best to avoid
calling the free in the first place (caller) or using  g_free() in qemu_vfree().

Best regards,
-Gonglei

>  From section 7.20.3.2/2 of the C99 standard:
> The free function causes the space pointed to by ptr to be deallocated, that 
> is,
> made available for further allocation. If ptr is a null pointer, no action 
> occurs.
> 
>> Signed-off-by: Gonglei <address@hidden>
>> ---
>>   util/oslib-posix.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
>> index 016a047..ca435d0 100644
>> --- a/util/oslib-posix.c
>> +++ b/util/oslib-posix.c
>> @@ -153,7 +153,7 @@ void *qemu_anon_ram_alloc(size_t size)
>>   void qemu_vfree(void *ptr)
>>   {
>>       trace_qemu_vfree(ptr);
>> -    free(ptr);
>> +    g_free(ptr);
>>   }
>>
>>   void qemu_anon_ram_free(void *ptr, size_t size)
>>
> 
> 






reply via email to

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