On Tue, Mar 15, 2011 at 11:02:38AM +0100, Jim Meyering wrote:
> > Instead of "please let us know", maybe recommend using
> > __builtin_expect instead? E.g. something like
> >
> > if (__builtin_expect (ptr != NULL, 0))
> >     free (ptr);
> 
> Good idea.  Thanks.
> Though how about avoiding the double negative?
> 
>    if (__builtin_expect (ptr == NULL, 1))
>      free (ptr);

What double negative?  if (__builtin_expect (ptr != NULL, 0)) free (ptr);
is certainly correct, the latter is wrong, it will leak memory.
It will call free only if ptr is NULL, i.e. do a useless free (NULL),
if it is non-NULL, it will not do anything.
You could do
  if (!__builtin_expect (ptr == NULL, 1))
    free (ptr);
but that doesn't seem to be nicer or clearer than
  if (__builtin_expect (ptr != NULL, 0))
    free (ptr);

        Jakub

Reply via email to