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.
This commit is contained in:
Bernhard Miklautz 2013-10-02 17:21:56 +02:00
parent 3fb2724536
commit 5c3ce890b1

View File

@ -24,6 +24,7 @@
#include <winpr/handle.h>
#include <winpr/thread.h>
#include <fcntl.h>
/**
* 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<maxfd; fd++)
close(fd);
#endif // __sun
if (token)
{