bug-bash
[Top][All Lists]
Advanced

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

Re: unnecessary {de,}alloc wrappers?


From: Ondrej Oprala
Subject: Re: unnecessary {de,}alloc wrappers?
Date: Tue, 01 Apr 2014 23:29:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

On 04/01/2014 08:21 PM, Eric Blake wrote:
On 04/01/2014 11:36 AM, Ondrej Oprala wrote:

Bruno Haible argued that the cost of a redundant if conditional is
cheaper than the cost of a function call in profiling runs, at least in
the portions of gnulib where he used that idiom.  Personally, I like
getting rid of the redundant if (I think the extra CPU cycles spent are
in the noise, until given a profile dump that proves otherwise).
Hmm, is that still up-to-date information?
Doing
$ git grep -B2 '\bfree\(.*;'
on glibc's and gnulib's upstream repo shows no occurences of code such
as "if (foobar) free(foobar);".
Gnulib comes with a script, build-aux/useless-if-before-free, for
identifying such instances.  Despite your claim of not finding any
instances in gnulib, this script found several, such as:

./lib/glob.c: if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
           free (pglob->gl_pathv[pglob->gl_offs + i]);
./lib/csharpcomp.c: if (line[0] != NULL)
         free (line[0]);
./lib/csharpcomp.c: if (line[1] != NULL)
         free (line[1]);
./lib/fstrcmp.c: if (buffer != NULL)
         free (buffer);
./lib/vasnprintf.c: if (tmp_roomptr != NULL)
     free (tmp_roomptr);
You're right, my regex was sloppy, '\bfree ?\(.*;' would have been better.
However, it's still quite rare in the code.
Either way, I find both of these code snippets very redundant.
As do I, but I'm not the one in charge of deciding whether to clean the
code base up to satisfy the useless-if-before-free script.

Thanks,
Ondrej



reply via email to

[Prev in Thread] Current Thread [Next in Thread]