1
0

Fixed bug in freeing NULL pointers

This commit is contained in:
Tycho 2014-05-25 17:48:40 +01:00
parent 8be3a8f7dc
commit 2591087385

View File

@ -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);