Remove uninitialised bytes
[platform/framework/native/channel-service.git] / src / IpcServer.cpp
index 02023d0..f6b2712 100644 (file)
@@ -38,6 +38,8 @@
 
 #include <ipc/ipc_message.h>
 
+#include <app_manager.h>
+
 #include <FBaseRtMutex.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
@@ -288,8 +290,7 @@ CATCH:
 struct HelloMessage
 {
        int pid;
-       bool reverse;  // true if the connection is for reverse message
-       char appId[256];
+       int reverse;  // if the connection is for reverse message
 };
 
 gboolean
@@ -317,7 +318,6 @@ IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoin
        SysTryCatch(NID_IO, client != -1, , E_SYSTEM, "[E_SYSTEM] Accept failed.");
 
        read(client, &helloMessage, sizeof(helloMessage));
-       helloMessage.appId[255] = '\0';
 
        pChannel = g_io_channel_unix_new(client);
        SysTryCatch(NID_IO, pChannel != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
@@ -336,17 +336,23 @@ IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoin
 
                pClientInfo->pIpcServer = pIpcServer;
                pClientInfo->clientId = helloMessage.pid;
-               pClientInfo->appId.Append((wchar_t*) helloMessage.appId);
+
+               char* pAppId = NULL;
+               int ret = app_manager_get_app_id(helloMessage.pid, &pAppId);
+               SysTryCatch(NID_IO, ret >= 0, delete pClientInfo, E_SYSTEM, "[E_SYSTEM] Failed to get_app_id: %d", ret);
+
+               pClientInfo->appId = pAppId;
+               free(pAppId);
+
                pClientInfo->pReverseChannel = null;
 
                pIpcServer->__clients[helloMessage.pid] = pClientInfo;
-
                pIpcServer->__pCurrentClientInfo = pClientInfo;
                pIpcServer->__pListener->OnIpcClientConnected(*pIpcServer, helloMessage.pid);
                pIpcServer->__pCurrentClientInfo = null;
        }
 
-       if (helloMessage.reverse)
+       if (helloMessage.reverse != 0)
        {
                pClientInfo->pReverseChannel = pChannel;
        }