From a967eec6b573d9bec825b0628339bce800df6b49 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Fri, 5 Jan 2024 11:51:49 +0100 Subject: [PATCH] [PATCH] Don't leak file descriptors when spawning new workers By default we inherit file descriptors from the parent in the worker process. This is a leak of resources since the worker won't be able to do anything with them. Also, in the case of CIFS this causes locks which might lead to bad surprises in the parent process. Gbp-Pq: Name fix_cifs_file_locks.patch --- src/kioslave/kioslave.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/kioslave/kioslave.cpp b/src/kioslave/kioslave.cpp index fcd15ef..6873003 100644 --- a/src/kioslave/kioslave.cpp +++ b/src/kioslave/kioslave.cpp @@ -18,6 +18,10 @@ #include #include +#ifdef Q_OS_UNIX +#include +#endif + #ifdef Q_OS_WIN #include #include @@ -40,6 +44,17 @@ extern "C" KIO::AuthInfo *_kioslave_init_kio() int main(int argc, char **argv) { +#ifdef Q_OS_UNIX + int max_fd = INT_MAX; + struct rlimit limit; + if (getrlimit(RLIMIT_NOFILE, &limit) == 0) { + max_fd = limit.rlim_cur; + } + for (int fd = STDERR_FILENO + 1; fd < max_fd; fd++) { + ::close(fd); + } +#endif + if (argc < 5) { fprintf(stderr, "Usage: kioslave5 \n\nThis program is part of KDE.\n"); return 1; -- 2.30.2