From: Hwankyu Jhun Date: Fri, 15 Mar 2019 11:02:24 +0000 (+0900) Subject: Fix fd leak X-Git-Tag: submit/tizen/20190318.041346~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a344342db783c78f184a050b4aa75d938a0e122b;p=platform%2Fcore%2Fappfw%2Frpc-port.git Fix fd leak Change-Id: I0a405972403b36cfb90e66ff73b2f36746c9a672 Signed-off-by: Hwankyu Jhun --- diff --git a/src/stub-internal.cc b/src/stub-internal.cc index 696eb6b..d6c85a0 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -81,6 +81,18 @@ std::shared_ptr Stub::FindDelegatePort( return {}; } +void Stub::RemoveAcceptedPorts(std::string instance) { + auto iter = ports_.begin(); + while (iter != ports_.end()) { + if ((*iter)->GetInstance().compare(instance) == 0) { + LOGI("Close: fd(%d)", (*iter)->GetFd()); + iter = ports_.erase(iter); + } else { + iter++; + } + } +} + gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, gpointer data) { Stub* stub = static_cast(data); @@ -92,7 +104,7 @@ gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { LOGW("Socket was disconnected from proxy. fd(%d)", fd); stub->listener_->OnDisconnected(p->GetId(), p->GetInstance()); - stub->ports_.remove(p); + stub->RemoveAcceptedPorts(p->GetInstance()); if (aul_rpc_port_notify_rpc_finished() != AUL_R_OK) LOGW("Failed to notify rpc finished"); @@ -106,7 +118,7 @@ gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, if (ret != 0) { LOGW("Invalid protocol"); stub->listener_->OnDisconnected(p->GetId(), p->GetInstance()); - stub->ports_.remove(p); + stub->RemoveAcceptedPorts(p->GetInstance()); if (aul_rpc_port_notify_rpc_finished() != AUL_R_OK) LOGW("Failed to notify rpc finished"); @@ -134,7 +146,7 @@ gboolean Stub::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, if (aul_rpc_port_notify_rpc_finished() != AUL_R_OK) LOGW("Failed to notify rpc finished"); } - stub->ports_.remove(p); + stub->RemoveAcceptedPorts(p->GetInstance()); break; } } diff --git a/src/stub-internal.h b/src/stub-internal.h index e3408f2..cff2e7b 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -81,6 +81,7 @@ class Stub : private FdBroker::IEventListener { gpointer data); void OnFdReceived(const std::string& sender, int fds[2]) override; + void RemoveAcceptedPorts(std::string instance); private: std::list> ports_;