Ensure we check for null when freeing from the memory pool 13/252213/3
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 25 Jan 2021 19:18:14 +0000 (19:18 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 25 Jan 2021 20:10:21 +0000 (20:10 +0000)
Change-Id: Ifd805f9cd0476864455dfc1751e4f110e1ea6846

dali/internal/common/fixed-size-memory-pool.cpp

index 29723b1..a7543bf 100644 (file)
@@ -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 );
+  }
 }