Fixed bug in freeing NULL pointers
This commit is contained in:
parent
8be3a8f7dc
commit
2591087385
@ -34,13 +34,12 @@ class cAllocationPool {
|
|||||||
{
|
{
|
||||||
if (m_FreeList.size() <= BufferSize)
|
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();
|
m_Callbacks->OnStartingUsingBuffer();
|
||||||
}
|
}
|
||||||
@ -51,7 +50,6 @@ class cAllocationPool {
|
|||||||
return Allocate();
|
return Allocate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// placement new, used to initalize the object
|
// placement new, used to initalize the object
|
||||||
T* ret = new (m_FreeList.front()) T;
|
T* ret = new (m_FreeList.front()) T;
|
||||||
m_FreeList.pop_front();
|
m_FreeList.pop_front();
|
||||||
@ -59,6 +57,10 @@ class cAllocationPool {
|
|||||||
}
|
}
|
||||||
void Free(T* ptr)
|
void Free(T* ptr)
|
||||||
{
|
{
|
||||||
|
if (ptr == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
// placement destruct.
|
// placement destruct.
|
||||||
ptr->~T();
|
ptr->~T();
|
||||||
m_FreeList.push_front(ptr);
|
m_FreeList.push_front(ptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user