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:
parent
3fb2724536
commit
5c3ce890b1
@ -24,6 +24,7 @@
|
|||||||
#include <winpr/handle.h>
|
#include <winpr/handle.h>
|
||||||
|
|
||||||
#include <winpr/thread.h>
|
#include <winpr/thread.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateProcessA
|
* CreateProcessA
|
||||||
@ -222,6 +223,19 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
/* child process */
|
/* 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)
|
if (token)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user