Disconnect client socket after all use in PkgInfoClient (#85)
author김일호/Tizen Platform Lab(SR)/Engineer/삼성전자 <ilho159.kim@samsung.com>
Thu, 25 Feb 2021 03:06:49 +0000 (12:06 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 25 Feb 2021 03:06:49 +0000 (12:06 +0900)
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/client/pkginfo_client.cc
src/client/pkginfo_client.hh

index 312d265..a4f4b99 100644 (file)
@@ -35,17 +35,24 @@ PkgInfoClient::PkgInfoClient(
   socket_ = std::make_unique<pkgmgr_common::socket::ClientSocket>(SOCK_PATH);
 }
 
+PkgInfoClient::~PkgInfoClient() {
+  if (socket_ != nullptr)
+    socket_->Disconnect();
+}
+
 bool PkgInfoClient::SendRequest() {
   if (socket_ == nullptr) return false;
 
   if (!socket_->Connect()) {
     LOGE("Failed to connect client socket, try to direct access");
+    socket_->Disconnect();
     is_offline_ = true;
     return RequestHandlerDirectAccess();
   }
 
   if (socket_->SendData(&req_type_, sizeof(req_type_)) != 0) {
     LOGE("fail to send data");
+    socket_->Disconnect();
     return false;
   }
 
@@ -56,11 +63,13 @@ bool PkgInfoClient::SendRequest() {
 
   if (socket_->SendData(&len, sizeof(len)) != 0) {
     LOGE("fail to send data");
+    socket_->Disconnect();
     return false;
   }
 
   if (socket_->SendData(&raw[0], len) != 0) {
     LOGE("Fail to send data");
+    socket_->Disconnect();
     return false;
   }
 
@@ -76,20 +85,24 @@ PkgInfoClient::GetResultParcel() {
   int len = 0;
   if (socket_->ReceiveData(&len, sizeof(len)) != 0) {
     LOGE("Fail to receive data");
+    socket_->Disconnect();
     return nullptr;
   }
 
   unsigned char* raw = new (std::nothrow) unsigned char[len];
   if (raw == nullptr) {
     LOGE("Out of memory");
+    socket_->Disconnect();
     return nullptr;
   }
 
   if (socket_->ReceiveData(raw, len) != 0) {
     LOGE("Fail to receive data");
+    socket_->Disconnect();
     delete[] raw;
     return nullptr;
   }
+  socket_->Disconnect();
 
   auto res = pkgmgr_common::parcel::ParcelableFactory::GetInst().CreateParcel(
       raw, len);
index f89e761..12430ad 100644 (file)
@@ -17,6 +17,7 @@ class PkgInfoClient {
  public:
   PkgInfoClient(std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcel,
       uid_t uid, pkgmgr_common::ReqType req_type);
+  ~PkgInfoClient();
   bool SendRequest();
   std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> GetResultParcel();