From: Kevin Ottens Date: Fri, 5 Jan 2024 10:51:49 +0000 (+0100) Subject: [PATCH] Don't leak file descriptors when spawning new workers X-Git-Tag: archive/raspbian/5.116.0-1+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a967eec6b573d9bec825b0628339bce800df6b49;p=kio.git [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 --- 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;