git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jim Meyering <jim@meyering.net>
Cc: Jean-Luc Herren <jlh@gmx.ch>, git list <git@vger.kernel.org>
Subject: Re: [PATCH] Remove useless if-before-free tests.
Date: Fri, 22 Feb 2008 15:05:55 -0800	[thread overview]
Message-ID: <7vd4qo7fsc.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <87tzk0tzjz.fsf@rho.meyering.net> (Jim Meyering's message of "Fri, 22 Feb 2008 23:08:00 +0100")

Jim Meyering <jim@meyering.net> writes:

> This change removes all obvious useless if-before-free tests.
> E.g., it replaces code like this:
>
>         if (some_expression)
>                 free (some_expression);
>
> with the now-equivalent:
>
>         free (some_expression);
>
> ...
>
> If you're interested in automating detection of the useless
> tests, you might like the useless-if-before-free script in gnulib:
> [it *does* detect brace-enclosed free statements, and has a --name=S
>  option to make it detect free-like functions with different names]

While I have your attention ;-)

I am not interested in automating useless "if (x) free(x)"
tests, but one thing I recently wanted but did not know a handy
tool for was to find all the calls to free() that free a pointer
to an object of a particular type.  More specifically, we seem
to allocate and free many "struct commit_list", and I wanted to
introduce a custom bulk allocator.  Allocate many of them in a
block, hand out one by one, and tell callers to hand them back
not to free() but to the allocator so that it can keep the
returned ones on a linked list and hand them back again when the
next call wanted to allocate one without actually calling
xmalloc()).  But in order to do so, missed conversion from
malloc() to the custom allocator is not fatal (just wasteful),
but forgetting to convert free() really is.

I guess sparse could be hacked to do that, but do GNU folks have
some checker like that?

  reply	other threads:[~2008-02-22 23:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-17 21:58 [PATCH] Remove useless if-before-free tests Jim Meyering
2008-02-17 22:09 ` David Symonds
2008-02-18  9:18   ` Jim Meyering
2008-02-18  9:36     ` Junio C Hamano
2008-02-17 22:16 ` Johannes Schindelin
2008-02-18  9:01   ` Jim Meyering
2008-02-18 14:27 ` Jean-Luc Herren
2008-02-20 10:26   ` Jim Meyering
2008-02-22 17:18     ` Junio C Hamano
2008-02-22 17:35       ` Jim Meyering
2008-02-22 17:40         ` Junio C Hamano
2008-02-22 22:08           ` Jim Meyering
2008-02-22 23:05             ` Junio C Hamano [this message]
2008-02-24 18:15               ` Jim Meyering
2009-02-26 13:48                 ` Mike Ralphson
2008-02-26  6:59               ` Uwe Kleine-König
2008-02-23 13:30             ` Morten Welinder
2008-02-24 10:06               ` Johannes Schindelin

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=7vd4qo7fsc.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jim@meyering.net \
    --cc=jlh@gmx.ch \
    /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).