Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
diizy committed Nov 18, 2014
1 parent 75770b4 commit 9972cb3
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/core/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ void * MemoryManager::alloc( size_t size )
{
mp = &( *it );
}
++it;
}
s_poolMutex.unlock();

if( ptr )
{
s_pointerMutex.lock();
PtrInfo p;
p.chunks = requiredChunks;
p.memPool = mp;
p.chunks = requiredChunks;
p.memPool = mp;
s_pointerInfo[ptr] = p;
s_pointerMutex.unlock();
return ptr;
Expand All @@ -86,8 +87,8 @@ void * MemoryManager::alloc( size_t size )
{
s_pointerMutex.lock();
PtrInfo p;
p.chunks = requiredChunks;
p.memPool = mp;
p.chunks = requiredChunks;
p.memPool = mp;
s_pointerInfo[ptr] = p;
s_pointerMutex.unlock();
return ptr;
Expand All @@ -100,13 +101,17 @@ void * MemoryManager::alloc( size_t size )

void MemoryManager::free( void * ptr )
{
if( ptr == NULL ) return; // let's not try to deallocate null pointers, ok?
if( ptr == NULL )
{
qDebug( "MemoryManager: Null pointer deallocation attempted" );
return; // let's not try to deallocate null pointers, ok?
}

// fetch info on the ptr and remove
s_pointerMutex.lock();
if( ! s_pointerInfo.contains( ptr ) ) // if we have no info on ptr, fail loudly
{
qFatal( "MemoryManager.cpp: Couldn't find pointer info for pointer: %d", (intptr_t)ptr );
qFatal( "MemoryManager: Couldn't find pointer info for pointer: %p", ptr );
}
PtrInfo p = s_pointerInfo[ptr];
s_pointerInfo.remove( ptr );
Expand Down Expand Up @@ -151,8 +156,8 @@ void * MemoryPool::getChunks( int chunksNeeded )

// now find out if we have a long enough sequence of chunks in this pool
char last = 0;
int n = 0;
int index = -1;
intptr_t n = 0;
intptr_t index = -1;
bool found = false;

for( int i = 0; i < m_chunks; ++i )
Expand Down Expand Up @@ -182,7 +187,7 @@ void * MemoryPool::getChunks( int chunksNeeded )
if( found ) // if enough chunks found, return pointer to chunks
{
// set chunk flags to false so we know the chunks are in use
for( int i = 0; i < chunksNeeded; ++i )
for( intptr_t i = 0; i < chunksNeeded; ++i )
{
m_free[ index + i ] = 0;
}
Expand All @@ -198,7 +203,7 @@ void MemoryPool::releaseChunks( void * ptr, int chunks )
{
m_mutex.lock();

int start = ( (intptr_t)ptr - (intptr_t)m_pool ) / MM_CHUNK_SIZE;
intptr_t start = ( (intptr_t)ptr - (intptr_t)m_pool ) / MM_CHUNK_SIZE;
if( start < 0 )
{
qFatal( "MemoryManager: error at releaseChunks() - corrupt pointer info?" );
Expand Down

0 comments on commit 9972cb3

Please sign in to comment.