From 727b6871bc2a9615cb7fd089690d8586c4ad637b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 7 May 2015 17:45:34 -0400 Subject: [PATCH] Made uiFree(NULL) illegal to spot bugs. --- TODO.md | 1 - darwin/alloc.m | 2 +- unix/alloc.c | 2 ++ windows/alloc.c | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 39fc855f..666221ad 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ -- forbid free(NULL) to check for bugs - opposite side alignment control in uiBox - disabling containers on wine doesn't redraw children as disabled - test on real windows diff --git a/darwin/alloc.m b/darwin/alloc.m index 25e9ba21..611ed440 100644 --- a/darwin/alloc.m +++ b/darwin/alloc.m @@ -49,6 +49,6 @@ void *uiRealloc(void *p, size_t new) void uiFree(void *p) { if (p == NULL) - return; + complain("attempt to uiFree(NULL); there's a bug somewhere"); free(BASE(p)); } diff --git a/unix/alloc.c b/unix/alloc.c index b56116bd..fef348a4 100644 --- a/unix/alloc.c +++ b/unix/alloc.c @@ -39,5 +39,7 @@ void *uiRealloc(void *p, size_t new) void uiFree(void *p) { + if (p == NULL) + complain("attempt to uiFree(NULL); there's a bug somewhere"); g_free(BASE(p)); } diff --git a/windows/alloc.c b/windows/alloc.c index 961ff5a0..1acb069f 100644 --- a/windows/alloc.c +++ b/windows/alloc.c @@ -44,7 +44,7 @@ void *uiRealloc(void *p, size_t size) void uiFree(void *p) { if (p == NULL) - return; + complain("attempt to uiFree(NULL); there's a bug somewhere"); if (HeapFree(heap, 0, p) == 0) logLastError("error freeing memory in uiFree()"); }