From ddb4533affe337000b305be955284f244b99b97c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 12 Dec 2014 10:55:57 -0500 Subject: [PATCH] Defined tableFree(NULL). --- wintable/new/util.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wintable/new/util.h b/wintable/new/util.h index 7ed8e98..470cef5 100644 --- a/wintable/new/util.h +++ b/wintable/new/util.h @@ -15,7 +15,7 @@ static BOOL runHandlers(const handlerfunc list[], struct table *t, UINT uMsg, WP // memory allocation stuff // each of these functions do an implicit ZeroMemory() -// these also make tableRealloc(NULL, ...) act like realloc(NULL, ...) (that is, same as tableAlloc(...)/malloc(...)) +// these also make tableRealloc(NULL, ...)/tableFree(NULL) act like realloc(NULL, ...)/free(NULL) (that is, same as tableAlloc(...)/malloc(...) and a no-op, respectively) // we're using LocalAlloc() because: // - whether the malloc() family supports the last-error code is undefined // - the HeapAlloc() family DOES NOT support the last-error code; you're supposed to use Windows exceptions, and I can't find a clean way to do this with MinGW-w64 that doesn't rely on inline assembly or external libraries (unless they added __try/__except blocks) @@ -46,6 +46,8 @@ static void *tableRealloc(void *p, size_t size, const char *panicMessage) static void tableFree(void *p, const char *panicMessage) { + if (p == NULL) + return; if (LocalFree((HLOCAL) p) != NULL) panic(panicMessage); }