Fix memory leaks on response message
authorJoohyun Kim <joohyune.kim@samsung.com>
Tue, 16 Jul 2013 06:03:03 +0000 (15:03 +0900)
committerJoohyun Kim <joohyune.kim@samsung.com>
Tue, 16 Jul 2013 06:03:03 +0000 (15:03 +0900)
Change-Id: I239afaeee055da90158cfbf22162d2bc20d1a923
Signed-off-by: Joohyun Kim <joohyune.kim@samsung.com>
inc/FApp_CommunicationDispatcher.h
src/FApp_CommunicationDispatcher.cpp

index 529997a..e680baa 100644 (file)
@@ -89,11 +89,13 @@ private:
        Tizen::Base::Runtime::Mutex             __Mutex;
        Tizen::Base::Collection::HashMapT<Tizen::Base::String, _ICommunicationRequestListener*> __serviceProviderMap;
        static _CommunicationDispatcher*        __pCommunicationDispatcher;
+
        Tizen::App::AppId                       __currentPkgId;
        int                                     __currentPid;
 
        Tizen::Base::ComparerT<Tizen::Base::String>     __comparer;
        Tizen::Base::StringHashCodeProvider     __strHashCodeProvider;
+       Tizen::Base::Collection::ArrayList      __responseContainer;
 };     //_CommunicationDispatcher
 
 }} //Tizen::App
index a087fed..1a9ca16 100644 (file)
@@ -38,6 +38,7 @@ namespace
        const String COMMUNICATION_MUTEX_ID = L"osp.app.ipcserver.communicationdispatcher";
 }
 
+
 _CommunicationDispatcher* _CommunicationDispatcher::__pCommunicationDispatcher = null;
 
 _CommunicationDispatcher::_CommunicationDispatcher()
@@ -49,22 +50,26 @@ _CommunicationDispatcher::_CommunicationDispatcher()
 
        __pIpcServer = new (std::nothrow) _IpcServer();
        r = __pIpcServer->Construct(COMMUNICATION_DISPATCHER_IPC_ID, *this);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to IPC server initialize. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to IPC server initialize. [%s] Propaged.", GetErrorMessage(r));
 
        r = __pIpcServer->Start();
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to start IPC server. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to start IPC server. [%s] Propaged.", GetErrorMessage(r));
 
        r = __Mutex.Create(COMMUNICATION_MUTEX_ID);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to create mutex. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to create mutex. [%s] Propaged.", GetErrorMessage(r));
 
        __pAppManagerImpl = _AppManagerImpl::GetInstance();
        SysTryCatch(NID_APP, __pAppManagerImpl != null, r = E_SYSTEM, r, "It is failed to get _AppManagerImpl instance");
 
        r = __pAppManagerImpl->AddAppEventListener(*this);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to add event listener. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to add event listener. [%s] Propaged.", GetErrorMessage(r));
+
+       r = __serviceProviderMap.Construct(0, 0, __strHashCodeProvider, __comparer);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to initialize provider's map. [%s] Propaged.", GetErrorMessage(r));
+
+       r = __responseContainer.Construct();
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to create response container. [%s] Propaged.", GetErrorMessage(r));
 
-       __serviceProviderMap.Construct(0, 0, __strHashCodeProvider, __comparer);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to initialize provider's map. [%s] Propaged.", r);
 
 CATCH:
        SetLastResult(r);
@@ -74,13 +79,15 @@ _CommunicationDispatcher::~_CommunicationDispatcher()
 {
        result r = E_SUCCESS;
        r = __pIpcServer->Stop();
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to stop IPC server. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to stop IPC server. [%s] Propaged.", GetErrorMessage(r));
 
        r = __Mutex.Release();
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to release mutex. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to release mutex. [%s] Propaged.", GetErrorMessage(r));
 
        r = __pAppManagerImpl->RemoveAppEventListener(*this);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to remove event listener. [%s] Propaged.", r);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "It is failed to remove event listener. [%s] Propaged.", GetErrorMessage(r));
+
+       __responseContainer.RemoveAll(true);
 
 CATCH:
        delete __pIpcServer;
@@ -188,6 +195,8 @@ _CommunicationDispatcher::OnRequestOccured(const ArrayList& request, ArrayList*
        result r = E_SUCCESS;
        SysLog(NID_APP, "Application is requested by IPC, currentPkgId is %ls", __currentPkgId.GetPointer());
 
+       __responseContainer.RemoveAll(true);
+
        String* componentId = (String*)request.GetAt(0);
 
        if(componentId == null)
@@ -211,6 +220,8 @@ _CommunicationDispatcher::OnRequestOccured(const ArrayList& request, ArrayList*
        ArrayList* temp = const_cast<ArrayList*>(&request);
        temp->RemoveAll(true);
 
+       __responseContainer.AddItems(*response);
+
        return true;
 }