From 8bd7c79755c44b87c80071016bcab6c51983cfbc Mon Sep 17 00:00:00 2001 From: Phil Rosenthal Date: Mon, 16 Jun 2025 16:10:55 -0400 Subject: [PATCH] Fix file descriptor leak in session file saving When system.files.session.fdatasync is set to "no", file descriptors were not being closed after writing session files, causing a severe resource leak. Each save operation would leak one file descriptor. With hundreds of torrents, this leads to tens of thousands of leaked file descriptors within hours, mostly pointing to deleted session files. This can exhaust the system's file descriptor limit and cause rtorrent to fail when opening new files. The fix moves the close() call outside the fdatasync conditional block, ensuring file descriptors are always properly closed regardless of the fdatasync setting. --- src/core/download_store.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/download_store.cc b/src/core/download_store.cc index 006e4b5d..5f857a24 100644 --- a/src/core/download_store.cc +++ b/src/core/download_store.cc @@ -100,9 +100,10 @@ DownloadStore::write_bencode(const std::string& filename, const torrent::Object& #else fdatasync(fd); #endif - ::close(fd); } + ::close(fd); + return true; download_store_save_error: