Fix the leaked memory on ObjectManagerImpl
authorJaesung Ku <jaesung.ku@samsung.com>
Mon, 19 Aug 2013 13:48:50 +0000 (22:48 +0900)
committerJaesung Ku <jaesung.ku@samsung.com>
Mon, 19 Aug 2013 13:50:43 +0000 (22:50 +0900)
Change-Id: I9e17d3c432a4082d6bde0f9893728e285daf7615
Signed-off-by: Jaesung Ku <jaesung.ku@samsung.com>
src/base/inc/FBase_ObjectManagerImpl.h

index 56d34db..ee425c7 100644 (file)
@@ -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 <int>(__slotCount - __freeSlots.GetCount());
 
-               r = __pLock->Release();
+               r = __lock.Release();
                SysTryLog(NID_BASE, !IsFailed(r), "Failed to release mutex");
 
                return cnt;
@@ -403,7 +396,7 @@ private:
        unsigned int __slotCount;
        unsigned int __slotCapacity;
        Tizen::Base::Collection::LinkedListT<unsigned int> __freeSlots;
-       Tizen::Base::Runtime::Mutex* __pLock;
+       mutable Tizen::Base::Runtime::Mutex __lock;
 
 };
 }} // Tizen::Base