Skip to content

Commit

Permalink
AK+ProtocolServer: Properly close download stream fd's
Browse files Browse the repository at this point in the history
This makes the issue of running out of openable pipes in the
ProtocolServer process much less likely (but still possible).
  • Loading branch information
alimpfard authored and awesomekling committed Dec 30, 2020
1 parent bdd4b99 commit 6422a04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion AK/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class InputFileStream : public InputStream {
~InputFileStream()
{
if (m_file) {
fflush(m_file);
if (m_owned)
fflush(m_file);
fclose(m_file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion Services/ProtocolServer/ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ OwnPtr<Messages::ProtocolServer::StartDownloadResponse> ClientConnection::handle
auto id = download->id();
auto fd = download->download_fd();
m_downloads.set(id, move(download));
return make<Messages::ProtocolServer::StartDownloadResponse>(id, fd);
auto response = make<Messages::ProtocolServer::StartDownloadResponse>(id, fd);
response->on_destruction = [fd] { close(fd); };
return response;
}

OwnPtr<Messages::ProtocolServer::StopDownloadResponse> ClientConnection::handle(const Messages::ProtocolServer::StopDownload& message)
Expand Down

0 comments on commit 6422a04

Please sign in to comment.