On Thu, Jul 31, 2014 at 10:32:07AM -0400, sven falempin wrote: > On Thu, Jul 31, 2014 at 6:39 AM, Fritjof Bornebusch <[email protected]> > wrote: > > On Wed, Jul 30, 2014 at 07:37:29PM -0700, patrick keshishian wrote: > >> 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; > >> > > That is true, but free() can handle NULL itself: > > > > ... > > /* This is legal. */ > > if (ptr == NULL) > > return; > > .... > > > > That's why there is no need, to use a condition like: > > if(ptr == NULL) > > errx(1, "xfree: NULL pointer given as argument"); > > > >> --patrick > >> > > fritjof > > > > For educational purpose i guess humanity need a <free(NULL) is valid> T shirt, > i learned it in the mailing list around a year ago. > > Maybe the back would be if not, patch your OS, or better use OpenBSD > That would be very cool!
> -- > --------------------------------------------------------------------------------------------------------------------- > () ascii ribbon campaign - against html e-mail > /\ >
