From 25910873852252fb388059e78d88a293ccd9d797 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 25 May 2014 17:48:40 +0100 Subject: Fixed bug in freeing NULL pointers --- src/AllocationPool.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b3818e8b1..643b44a6d 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -34,22 +34,20 @@ class cAllocationPool { { if (m_FreeList.size() <= BufferSize) { - try + void * space = malloc(sizeof(T)); + if (space != NULL) { - return new(malloc(sizeof(T))) T; + return new(space) T; } - catch (std::bad_alloc&) + else if (m_FreeList.size() == BufferSize) { - if (m_FreeList.size() == BufferSize) - { - m_Callbacks->OnStartingUsingBuffer(); - } - else if (m_FreeList.empty()) - { - m_Callbacks->OnBufferEmpty(); - // Try again until the memory is avalable - return Allocate(); - } + m_Callbacks->OnStartingUsingBuffer(); + } + else if (m_FreeList.empty()) + { + m_Callbacks->OnBufferEmpty(); + // Try again until the memory is avalable + return Allocate(); } } // placement new, used to initalize the object @@ -59,6 +57,10 @@ class cAllocationPool { } void Free(T* ptr) { + if (ptr == NULL) + { + return; + } // placement destruct. ptr->~T(); m_FreeList.push_front(ptr); -- cgit v1.2.3