--- freeciv/common/mem.c.orig Fri Aug 17 18:03:28 2001 +++ freeciv/common/mem.c Fri Aug 17 18:04:04 2001 @@ -44,6 +44,18 @@ } /********************************************************************** + Do whatever we should do when free is passed a NULL pointer. + Right now it triggers an assert and dies. +**********************************************************************/ +static void handle_free_failure(void *ptr, const char *called_as, + int line, const char *file) +{ + freelog(LOG_FATAL, _("NULL pointer passed to %s at line %d of %s."), + called_as, line, file); + assert(ptr); +} + +/********************************************************************** Function used by fc_malloc macro, malloc() replacement No need to check return value. **********************************************************************/ @@ -108,6 +120,19 @@ ptr = fc_real_malloc(size, called_as, line, file); memset(ptr, 0, size); return ptr; +} + +/*************************************************************** + Function used by fc_free macro, free() replacement. + Helps to prevent undefined heap corruptions. +***************************************************************/ +void fc_real_free(void *ptr, const char *called_as, + int line, const char *file) +{ + if(!ptr) + handle_free_failure(ptr, called_as, line, file); + + free(ptr); } /***************************************************************