From: solar <> Date: Sun, 20 Feb 2011 20:48:48 +0000 (+0000) Subject: Fix for #42 - free( NULL ) must not fail. X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=commitdiff_plain;h=f12696b39491a60010cc28c029133833856b5b85 Fix for #42 - free( NULL ) must not fail. --- diff --git a/functions/stdlib/free.c b/functions/stdlib/free.c index 43de129..4370487 100644 --- a/functions/stdlib/free.c +++ b/functions/stdlib/free.c @@ -22,6 +22,10 @@ extern struct _PDCLIB_headnode_t _PDCLIB_memlist; void free( void * ptr ) { + if ( ptr == NULL ) + { + return; + } ptr = (void *)( (char *)ptr - sizeof( struct _PDCLIB_memnode_t ) ); ( (struct _PDCLIB_memnode_t *)ptr )->next = NULL; if ( _PDCLIB_memlist.last != NULL ) @@ -39,10 +43,12 @@ void free( void * ptr ) #ifdef TEST #include <_PDCLIB_test.h> +#include int main( void ) { - /* tests covered in malloc test driver */ + free( NULL ); + TESTCASE( true ); return TEST_RESULTS; }