[Xcb] [PATCH] util-cursor: Fix minor memleak and fix the RENDER version check

Uli Schlachter psychon at znc.in
Thu Sep 19 11:10:51 PDT 2013


Hi,

On 19.09.2013 19:31, Josh Triplett wrote:
> On Thu, Sep 19, 2013 at 07:09:01PM +0200, Uli Schlachter wrote:
>> On 19.09.2013 18:47, Bart Massey wrote:
>>> I'm confused about the first patch. Shouldn't you be checking whether
>>> the resource string is null before freeing it, rather than freeing it
>>> unconditionally?
>>
>> free(NULL) is fine. First result for "free null" on Google is:
>>
>> http://stackoverflow.com/questions/1938735/does-freeptr-where-ptr-is-null-corrupt-memory
>>
>> Or, quoting free(3) (the part about free):
>>
>>   If ptr is NULL, no operation is performed.
>>
>> Really, everyone who writes something like if (foo != NULL) free(foo); should be
>> taught this.
>>
>> According to other Google results, even c89 says this already.
> 
> And generalizing, any type of memory reclamation function should follow
> that pattern: if you write a function foo_free or foo_destroy or
> similar, make it accept NULL and no-op, rather than making your callers
> do that.

Uhm, should I turn the attached diff into a proper commit? :-P
-- 
"For saving the Earth.. and eating cheesecake!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: disconnect.patch
Type: text/x-patch
Size: 346 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20130919/a62595b7/attachment.bin>


More information about the Xcb mailing list