From 46a624bbf26161354f2702d296b2dea077005cc1 Mon Sep 17 00:00:00 2001 From: Jaesung Ku Date: Mon, 19 Aug 2013 22:48:50 +0900 Subject: [PATCH] Fix the leaked memory on ObjectManagerImpl Change-Id: I9e17d3c432a4082d6bde0f9893728e285daf7615 Signed-off-by: Jaesung Ku --- src/base/inc/FBase_ObjectManagerImpl.h | 39 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/base/inc/FBase_ObjectManagerImpl.h b/src/base/inc/FBase_ObjectManagerImpl.h index 362c451..ee425c7 100644 --- a/src/base/inc/FBase_ObjectManagerImpl.h +++ b/src/base/inc/FBase_ObjectManagerImpl.h @@ -48,10 +48,7 @@ public: __slotCapacity = DEFAULT_CAPACITY; __pSlots = new _HandleElement[__slotCapacity]; - __pLock = new (std::nothrow) Tizen::Base::Runtime::Mutex(); - SysTryLog(NID_BASE, __pLock != null, "Failed to allocate the mutex instance"); - - result r = __pLock->Create(); + result r = __lock.Create(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to create the mutex instance"); } @@ -63,7 +60,6 @@ public: virtual ~_ObjectManagerImpl(void) { delete[] __pSlots; - //delete __pLock; } /** @@ -82,10 +78,7 @@ public: __pSlots[i] = objectManagerImpl.__pSlots[i]; } - __pLock = new (std::nothrow) Tizen::Base::Runtime::Mutex(); - SysTryLog(NID_BASE, __pLock != null, "Failed to allocate the mutex instance"); - - result r = __pLock->Create(); + result r = __lock.Create(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to create the mutex instance"); } @@ -128,7 +121,7 @@ public: */ int Register(void* pObject) { - result r = __pLock->Acquire(); + result r = __lock.Acquire(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to acquire mutex"); _Handle handle; @@ -161,7 +154,7 @@ public: __pSlots[index].__pObject = pObject; } - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); return handle.__handle; @@ -179,7 +172,7 @@ public: */ void* Unregister(unsigned int handle) { - result r = __pLock->Acquire(); + result r = __lock.Acquire(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to acquire mutex"); void* pObject = null; @@ -187,7 +180,7 @@ public: if (index >= __slotCount) { - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); SetLastResult(E_OBJ_NOT_FOUND); @@ -197,7 +190,7 @@ public: _HandleElement& element = __pSlots[index]; if (element.__id != ((_Handle*)&handle)->__id) { - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); SetLastResult(E_OBJ_NOT_FOUND); @@ -211,7 +204,7 @@ public: __freeSlots.Add(index); - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); return pObject; @@ -228,14 +221,14 @@ public: */ const void* GetObject(unsigned int handle) const { - result r = __pLock->Acquire(); + result r = __lock.Acquire(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to acquire mutex"); const unsigned int index = ((_Handle*)&handle)->__index; if (index >= __slotCount) { - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); SetLastResult(E_OBJ_NOT_FOUND); @@ -245,14 +238,14 @@ public: const _HandleElement& element = __pSlots[index]; if (element.__id != ((_Handle*)&handle)->__id) { - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); SetLastResult(E_OBJ_NOT_FOUND); return null; } - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); return element.__pObject; @@ -281,12 +274,12 @@ public: */ int GetObjectCount(void) const { - result r = __pLock->Acquire(); + result r = __lock.Acquire(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to acquire mutex"); int cnt = static_cast (__slotCount - __freeSlots.GetCount()); - r = __pLock->Release(); + r = __lock.Release(); SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex"); return cnt; @@ -403,8 +396,8 @@ private: unsigned int __slotCount; unsigned int __slotCapacity; Tizen::Base::Collection::LinkedListT __freeSlots; - Tizen::Base::Runtime::Mutex* __pLock; + mutable Tizen::Base::Runtime::Mutex __lock; }; }} // Tizen::Base -#endif // _FBASE_INTERNAL_OBJECT_MANAGER_IMPL_H_ \ No newline at end of file +#endif // _FBASE_INTERNAL_OBJECT_MANAGER_IMPL_H_ -- 2.7.4