git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Remove useless if-before-free tests.

From
Jim Meyering <jim@meyering.net>
Date
Feb 24, 2008, 18:15 UTC
Message-ID
<877igup6fl.fsf@rho.meyering.net>
In-Reply-To
<7vd4qo7fsc.fsf@gitster.siamese.dyndns.org>

Junio C Hamano <gitster@pobox.com> wrote: ...

Show 6 quoted lines
>> 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 ;-)
Hi Jun,
No excuse required ;-)
> I am not interested in automating useless "if (x) free(x)" tests,

Yeah, that particular one is not a big deal, but whenever I take the time to make a sweeping change, I find it's worth a little more to automate a check to preserve the goal state.

> 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.
...
> I guess sparse could be hacked to do that, but do GNU folks have
> some checker like that?

A general purpose tool to do something like that would be very useful. I thought of cscope and eclipse, but as far as I know, neither of them can perform such a query.

This made me think of the dwarves package/paper:
    7 dwarves
    https://ols2006.108.redhat.com/2007/Reprints/melo-Reprint.pdf

This looked promising at first, but it annotates function _definitions_ for run-time data collection, while you want to look at uses, which can be done statically:

    3.4   ctracer
    A class tracer, ctracer is an experiment in creating valid source
    code from the DWARF information.  For ctracer a method is any
    function that receives as one of its parameters a pointer to a
    specified struct. It looks for all such methods and generates
    kprobes entry and exit functions. At these probe points it
    collects information about the data structure internal state,
    saving the values in its members in that point in time, and
    records it in a relay buffer. The data is later collected in
    userspace and post-processed, generating html + CSS callgraphs.
Too bad coverity is closed-source.  I'll bet it could do this easily.
Maybe hacking sparse is the way to go, after all.
Previous: Junio C HamanoNext: Mike Ralphson
Message 14 of 18 in “Remove useless if-before-free tests.”
  1. Remove useless if-before-free tests.Jim Meyering, Feb 17, 2008
  2. David SymondsFeb 17, 2008
  3. Jim MeyeringFeb 18, 2008
  4. Junio C HamanoFeb 18, 2008
  5. Johannes SchindelinFeb 17, 2008
  6. Jim MeyeringFeb 18, 2008
  7. Jean-Luc HerrenFeb 18, 2008
  8. Jim MeyeringFeb 20, 2008
  9. Junio C HamanoFeb 22, 2008
  10. Jim MeyeringFeb 22, 2008
  11. Junio C HamanoFeb 22, 2008
  12. Jim MeyeringFeb 22, 2008
  13. Junio C HamanoFeb 22, 2008
  14. Jim MeyeringFeb 24, 2008
  15. Mike RalphsonFeb 26, 2009
  16. Uwe Kleine-KönigFeb 26, 2008
  17. Morten WelinderFeb 23, 2008
  18. Johannes SchindelinFeb 24, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.