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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Meyering <jim@xxxxxxxxxxxx> 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?
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux