Fix an argument of Client::Recv() 96/256596/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 8 Apr 2021 01:17:32 +0000 (10:17 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 8 Apr 2021 01:34:45 +0000 (10:34 +0900)
The type of an argument is changed to Packet**.

Change-Id: I6a429014988308755c17b4d81dce42bc8f070dbc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
aul/app_manager/app_manager.cc
aul/component/component_port.cc
aul/socket/client.cc
aul/socket/client.hh

index 2832999..2362fc8 100644 (file)
@@ -76,7 +76,7 @@ std::unique_ptr<AppContext> AppManager::GetAppContext(int pid) {
 }
 
 std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
-  Packet recv_pkt;
+  Packet* recv_pkt = nullptr;
   try {
     Client client(PATH_AMD_SOCK);
     int ret = client.Send(packet);
@@ -85,7 +85,7 @@ std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
       return {};
     }
 
-    ret = client.Recv(recv_pkt);
+    ret = client.Recv(&recv_pkt);
     if (ret < 0) {
       set_last_result(aul_error_convert(ret));
       return {};
@@ -96,14 +96,15 @@ std::unique_ptr<AppContext> AppManager::GetAppContext(const Packet& packet) {
     return {};
   }
 
-  if (recv_pkt.GetCmd() != APP_GET_INFO_OK) {
+  std::unique_ptr<Packet> ptr(recv_pkt);
+  if (recv_pkt->GetCmd() != APP_GET_INFO_OK) {
     _E("Failed to find app context");
-    set_last_result(aul_error_convert(recv_pkt.GetCmd()));
+    set_last_result(aul_error_convert(recv_pkt->GetCmd()));
     return {};
   }
 
   set_last_result(AUL_R_OK);
-  tizen_base::Bundle b = recv_pkt.DataToBundle();
+  tizen_base::Bundle b = recv_pkt->DataToBundle();
   return std::unique_ptr<AppContext>(new (std::nothrow) AppContext(b));
 }
 
index 6b7fa5c..dfa3a90 100644 (file)
@@ -81,7 +81,7 @@ int ComponentPort::SendRequest(int cmd, int opt) {
   tizen_base::Bundle b;
   b.Add(AUL_K_COMPONENT_PORT, name_);
   Packet pkt(cmd, opt | AUL_SOCK_BUNDLE, b);
-  Packet recv_pkt;
+  Packet* recv_pkt = nullptr;
   try {
     Client client(PATH_AMD_SOCK);
     int ret = client.Send(pkt);
@@ -91,7 +91,7 @@ int ComponentPort::SendRequest(int cmd, int opt) {
     if (opt & AUL_SOCK_NOREPLY)
       return ret;
 
-    ret = client.Recv(recv_pkt);
+    ret = client.Recv(&recv_pkt);
     if (ret < 0)
       return aul_error_convert(ret);
   } catch (Exception& e) {
@@ -99,12 +99,13 @@ int ComponentPort::SendRequest(int cmd, int opt) {
     return aul_error_convert(e.GetErrorCode());
   }
 
-  if (recv_pkt.GetCmd() != cmd) {
+  std::unique_ptr<Packet> ptr(recv_pkt);
+  if (recv_pkt->GetCmd() != cmd) {
     _E("Invalid protocol");
     return AUL_R_ECOMM;
   }
 
-  b = recv_pkt.DataToBundle();
+  b = recv_pkt->DataToBundle();
   auto str = b.GetString(AUL_K_RESULT);
   int ret = std::stoi(str);
   if (ret < 0)
index 879dc8d..82fa292 100644 (file)
@@ -54,7 +54,7 @@ int Client::Send(const Packet& packet) {
   return Socket::Send(reinterpret_cast<void*>(&raw[0]), raw.size());
 }
 
-int Client::Recv(Packet& packet) {
+int Client::Recv(Packet** packet) {
   int cmd = -1;
   void* p = reinterpret_cast<void*>(&cmd);
   int ret = Socket::Recv(p, sizeof(cmd));
@@ -93,9 +93,11 @@ int Client::Recv(Packet& packet) {
   std::vector<unsigned char> data(buf, buf + size);
   delete[] buf;
 
-  packet.SetCmd(cmd);
-  packet.SetOpt(opt);
-  packet.SetData(data);
+  *packet = new (std::nothrow) Packet(cmd, opt, data);
+  if (*packet == nullptr) {
+    _E("Out of memory");
+        return -ENOMEM;
+  }
 
   return 0;
 }
index c54bb05..ca6a5cf 100644 (file)
@@ -26,7 +26,7 @@ class Client : public Socket {
  public:
   Client(std::string path, int timeout_msec = 5000);
   int Send(const Packet& packet);
-  int Recv(Packet& packet);
+  int Recv(Packet** packet);
 };
 
 }  // namespace aul