AmendHub

Download:

jcs

/

subtext

/

amendments

/

252

util: panic on xfree(NULL) and xfree(&NULL)


jcs made amendment 252 over 2 years ago
--- util.c Tue Sep 13 21:31:54 2022 +++ util.c Fri Sep 16 17:56:10 2022 @@ -203,10 +203,19 @@ void xfree(void *ptrptr) { unsigned long *addr = (unsigned long *)ptrptr; - void *ptr = (void *)*addr; + void *ptr; #ifdef MALLOC_DEBUG unsigned long n; +#endif + if (ptrptr == NULL) + panic("xfree(NULL)"); + + ptr = (void *)*addr; + if (ptr == NULL) + panic("xfree(&NULL) likely a double-free"); + +#ifdef MALLOC_DEBUG for (n = 0; n <= malloc_map_size; n++) { if (n == malloc_map_size) panic("xfree(0x%lx): can't find in alloc map, likely "