Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Aug 1998 09:26:15 +0200 (MET DST)
From:      Nick Hibma <nick.hibma@jrc.it>
To:        Warner Losh <imp@village.org>
Cc:        FreeBSD hackers mailing list <hackers@FreeBSD.ORG>
Subject:   Re: Realloc fix for review 
Message-ID:  <Pine.GSO.3.95q.980821092427.1847J-100000@elect8>
In-Reply-To: <199808210309.VAA26640@harmony.village.org>

next in thread | previous in thread | raw e-mail | index | archive | help
 > #include <stdlib.h>
 > 
 > void *
 > frealloc(void *ptr, size_t size)
 > {
 >     void *nptr;
 > 
 >     nptr = realloc(ptr, size);
 >     if (!nptr && ptr)
 >         free(ptr);
 >     return (nptr);
 > }
 > 
 > which does try to avoid calling free(NULL).
 > 
 > Warner


What about using a define in stdlib.h:
  
#define reallocf(ptr, size)     \
        { \
                void *nptr; \
                nptr = realloc(ptr,size); \
                if ( !nptr && ptr ) \
                        free(ptr) \
                nptr \
        }
 
Or at least, something along those lines. 

Nick

 
 
P.S.: About name space pollution: What about calling it
        reallocAndFreeAfterwardsIfReallocFails

You won't need a man page...




-- 
building: 27A
address:  STA-ISIS, T.P.270, Joint Research Centre, 21020 Ispra, Italy
tel.:     +39 332 78 9549
fax.:     +39 332 78 9185


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.3.95q.980821092427.1847J-100000>