From cbec05c4286b042fa3cd586e132925bbac1a3a7d Mon Sep 17 00:00:00 2001 From: cyberbotx Date: Sun, 19 Jul 2009 07:24:57 +0000 Subject: [PATCH] Fix for potentially undefined behavior in the Windows build, make the overloaded delete and delete[] operators check if the pointer is NULL before trying to use HeapFree(), thanks to Adam for pointing this out. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2385 5417fbe8-f217-4b02-8779-1006273d7864 --- src/win32_memory.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/win32_memory.cpp b/src/win32_memory.cpp index 9da1b7812..cf78a531a 100644 --- a/src/win32_memory.cpp +++ b/src/win32_memory.cpp @@ -42,7 +42,8 @@ void * ::operator new(size_t iSize) void ::operator delete(void *ptr) { - HeapFree(GetProcessHeap(), 0, ptr); + if (ptr) + HeapFree(GetProcessHeap(), 0, ptr); } void * operator new[](size_t iSize) { @@ -55,7 +56,8 @@ void * operator new[](size_t iSize) { void operator delete[](void *ptr) { - HeapFree(GetProcessHeap(), 0, ptr); + if (ptr) + HeapFree(GetProcessHeap(), 0, ptr); } #endif