From 9451fb127582b109bd4d68f111137b70c4ed4cdb Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 25 Jan 2021 19:18:14 +0000 Subject: [PATCH] Ensure we check for null when freeing from the memory pool Change-Id: Ifd805f9cd0476864455dfc1751e4f110e1ea6846 --- dali/internal/common/fixed-size-memory-pool.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dali/internal/common/fixed-size-memory-pool.cpp b/dali/internal/common/fixed-size-memory-pool.cpp index 29723b1..a7543bf 100644 --- a/dali/internal/common/fixed-size-memory-pool.cpp +++ b/dali/internal/common/fixed-size-memory-pool.cpp @@ -205,13 +205,16 @@ void* FixedSizeMemoryPool::Allocate() void FixedSizeMemoryPool::Free( void* memory ) { + if( memory ) + { #ifdef DEBUG_ENABLED - mImpl->CheckMemoryIsInsidePool( memory ); + mImpl->CheckMemoryIsInsidePool( memory ); #endif - // Add memory to head of deleted objects list. Store next address in the same memory space as the old object. - *( reinterpret_cast< void** >( memory ) ) = mImpl->mDeletedObjects; - mImpl->mDeletedObjects = memory; + // Add memory to head of deleted objects list. Store next address in the same memory space as the old object. + *( reinterpret_cast< void** >( memory ) ) = mImpl->mDeletedObjects; + mImpl->mDeletedObjects = memory; + } } void* FixedSizeMemoryPool::AllocateThreadSafe() @@ -222,8 +225,11 @@ void* FixedSizeMemoryPool::AllocateThreadSafe() void FixedSizeMemoryPool::FreeThreadSafe( void* memory ) { - Mutex::ScopedLock lock( mImpl->mMutex ); - Free( memory ); + if( memory ) + { + Mutex::ScopedLock lock( mImpl->mMutex ); + Free( memory ); + } } -- 2.7.4