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

Josh Triplett josh at joshtriplett.org
Thu Sep 19 10:31:53 PDT 2013


On Thu, Sep 19, 2013 at 07:09:01PM +0200, Uli Schlachter wrote:
> Hi,
> 
> 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.

- Josh Triplett


More information about the Xcb mailing list