On Wed, Jul 30, 2014 at 10:14:54PM +0200, Fritjof Bornebusch wrote:
> Hi tech,
>
> there is an unnecessary NULL check before calling free.
>
> fritjof
>
> Index: xmalloc.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 xmalloc.c
> --- xmalloc.c 7 Jun 2009 08:39:13 -0000 1.4
> +++ xmalloc.c 31 May 2014 19:19:18 -0000
> @@ -76,8 +76,6 @@ xrealloc(void *ptr, size_t nmemb, size_t
> void
> xfree(void *ptr)
> {
> - if (ptr == NULL)
> - errx(1, "xfree: NULL pointer given as argument");
> free(ptr);
> }
Going by this context, a quick grep in src/usr.bin/rcs, and
especially the error message, the NULL check's purpose is to
catach this condition.
The code you claim to correct:
> there is an unnecessary NULL check before calling free.
would have been of the form:
if (ptr != NULL) -or- if (ptr == NULL)
free(ptr); return;
--patrick