From 81c9291f4ef984aefd92f28339bd4ed97dfd3e65 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 20 May 2007 14:08:20 +0000 Subject: Throw bad alloc on out of memory, not return null, this is the correct behaviour according to the C++ standards git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7066 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/inspircd_memory_functions.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/win/inspircd_memory_functions.cpp b/win/inspircd_memory_functions.cpp index d03330bf5..7e2f23194 100644 --- a/win/inspircd_memory_functions.cpp +++ b/win/inspircd_memory_functions.cpp @@ -1,9 +1,16 @@ // Use the global heap for this process for all allocate/free operations. #include "inspircd_win32wrapper.h" +#include void * ::operator new(size_t iSize) { - return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iSize); // zero memory for unix compatibility + void* ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iSize); // zero memory for unix compatibility + /* This is the correct behaviour according to C++ standards for out of memory, + * not returning null -- Brain*/ + if (!ptr) + throw std::bad_alloc; + else + return ptr; } void ::operator delete(void * ptr) -- cgit v1.2.3