From 5c3ce890b1652cfbdd7cb4666900a985267d5544 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 2 Oct 2013 17:21:56 +0200 Subject: [PATCH] winpr-thread: close fds before exec new process Close all open file handles, except stdion/stdout/stderr before executing a new process to make sure that no file descriptors leak or kept open. --- winpr/libwinpr/thread/process.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/winpr/libwinpr/thread/process.c b/winpr/libwinpr/thread/process.c index 62d7f1faf..cc58e3667 100644 --- a/winpr/libwinpr/thread/process.c +++ b/winpr/libwinpr/thread/process.c @@ -24,6 +24,7 @@ #include #include +#include /** * CreateProcessA @@ -222,6 +223,19 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, if (pid == 0) { /* child process */ +#ifdef __sun + closefrom(3); +#else + int maxfd; +#ifdef F_MAXFD // on some BSD derivates + maxfd = fcntl(0, F_MAXFD); +#else + maxfd = sysconf(_SC_OPEN_MAX); +#endif + int fd; + for(fd=3; fd