bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] maint: enable the sc_avoid_if_before_free syntax-check


From: Bruno Haible
Subject: Re: [PATCH] maint: enable the sc_avoid_if_before_free syntax-check
Date: Thu, 12 Jul 2012 23:28:19 +0200
User-agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; )

Hi Jim,

> > Nowadays little code remains that is written for K&R C, and few minds 
> > program
> > for K&R C. Therefore the "if before free" cases that are remaining are
> > more likely to be intentional than before.
> 
> If only that were true.  I've just removed several hundreds of
> such uses from glusterfs.  From what I've seen, the majority of
> C/C++ developers attempt to avoid free(p) when p is NULL.

For C hackers, the p != NULL test may be intentional: they may want to save
a function call.

Whereas C++ programmers often add this test for a different reason:
C++ APIs are often not well documented (because C++ tends to make you
create huge, thoughtless APIs, not small and intelligent APIs), and so
the caller of a function never really knows whether NULL is a possible
return value. When you have gotten a core dump because your invocation
of a small function returned NULL instead of an empty list, 5 or 10 times
in the same week, you learn to add   if (p != NULL)   protections everywhere,
even where it's not needed.

Bruno




reply via email to

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