Release client instances 22/321022/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Nov 2024 00:16:06 +0000 (09:16 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Nov 2024 00:16:06 +0000 (09:16 +0900)
When creating the client channel is failed, we should release client instances.

Change-Id: I7d5c564cbc3ac0d6634d51d9e235187bde44aa84
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/rpc-port/proxy-internal.cc

index 809ab8456cd724600160744bc992e7c14cd2220f..c36d785b405cfc02e313a15bbb12fa720237e9ea 100644 (file)
@@ -131,15 +131,27 @@ int Proxy::Connect(bool sync) {
 
   ret =
       CreateClientChannel(instance, kPortTypeMainWrite, sync, &main_client_[1]);
-  if (ret != RPC_PORT_ERROR_NONE) return ret;
+  if (ret != RPC_PORT_ERROR_NONE) {
+    main_client_[0].reset();
+    return ret;
+  }
 
   ret = CreateClientChannel(instance, kPortTypeDelegateRead, sync,
                             &delegate_client_[0]);
-  if (ret != RPC_PORT_ERROR_NONE) return ret;
+  if (ret != RPC_PORT_ERROR_NONE) {
+    main_client_[1].reset();
+    main_client_[0].reset();
+    return ret;
+  }
 
   ret = CreateClientChannel(instance, kPortTypeDelegateWrite, sync,
                             &delegate_client_[1]);
-  if (ret != RPC_PORT_ERROR_NONE) return ret;
+  if (ret != RPC_PORT_ERROR_NONE) {
+    delegate_client_[0].reset();
+    main_client_[1].reset();
+    main_client_[0].reset();
+    return ret;
+  }
 
   auto peer_cred =
       std::unique_ptr<PeerCred>(PeerCred::Get(main_client_[0]->GetFd()));