Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] parse_object: check if buffer is non-NULL before freeing it

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:38

Linus Torvalds [off-list ref] writes:
On Sun, 27 Aug 2006, Junio C Hamano wrote:
quoted
Eh, free(NULL) should work just fine.  It is "other places" that
is misguided and needs to be fixed.
Well, some very old libraries will SIGSEGV on free(NULL). 

Admittedly those libraries are either very old or _very_ broken, but if 
you want to be strictly portable, you should not ever pass NULL to free(), 
unless you actually got it from a malloc(0) (and even then, it might be a 
really broken libc that just ran out of memory).
Fair enough, but I think there are many places we already assume
the library handles free(NULL) sensibly.
I actually suspect we should wrap all free() calls as "xfree()", which may 
also help us some day if we want to do any memory usage statistics.
That sounds sensible.

Another thing I was thinking about was to extend the existing
XMALLOC_POISON debugging to allow also xrealloc()'ed area.  That
would unfortunately involve wrapping strdup() and x*alloc() to
make sure all allocations we do go through xmalloc() and then
store the current allocation size somewhere hidden (immediately
before, perhaps) in the area xmalloc() returns, but at that
point running git under valgrind would probably be easier.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help