From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] parse_object: check if buffer is non-NULL before freeing it
Date: Sun, 27 Aug 2006 22:46:09 -0700 [thread overview]
Message-ID: <7v3bbhtntq.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0608272131020.27779@g5.osdl.org> (Linus Torvalds's message of "Sun, 27 Aug 2006 21:33:16 -0700 (PDT)")
Linus Torvalds <torvalds@osdl.org> writes:
> On Sun, 27 Aug 2006, Junio C Hamano wrote:
>>
>> 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.
prev parent reply other threads:[~2006-08-28 5:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-28 0:31 [PATCH] parse_object: check if buffer is non-NULL before freeing it Jonas Fonseca
2006-08-28 4:20 ` Junio C Hamano
2006-08-28 4:33 ` Linus Torvalds
2006-08-28 5:46 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v3bbhtntq.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).