From 6422a04cdae10f4e633cbc532ae576ceb23f791a Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 30 Dec 2020 21:05:54 +0330 Subject: [PATCH] AK+ProtocolServer: Properly close download stream fd's This makes the issue of running out of openable pipes in the ProtocolServer process much less likely (but still possible). --- AK/FileStream.h | 3 ++- Services/ProtocolServer/ClientConnection.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AK/FileStream.h b/AK/FileStream.h index 0355ec16f95..27138b0f347 100644 --- a/AK/FileStream.h +++ b/AK/FileStream.h @@ -54,8 +54,9 @@ public: ~InputFileStream() { if (m_file) { + fflush(m_file); if (m_owned) - fflush(m_file); + fclose(m_file); } } diff --git a/Services/ProtocolServer/ClientConnection.cpp b/Services/ProtocolServer/ClientConnection.cpp index eee7277869f..45ef0e2683d 100644 --- a/Services/ProtocolServer/ClientConnection.cpp +++ b/Services/ProtocolServer/ClientConnection.cpp @@ -72,7 +72,9 @@ OwnPtr ClientConnection::handle auto id = download->id(); auto fd = download->download_fd(); m_downloads.set(id, move(download)); - return make(id, fd); + auto response = make(id, fd); + response->on_destruction = [fd] { close(fd); }; + return response; } OwnPtr ClientConnection::handle(const Messages::ProtocolServer::StopDownload& message)