From 8a971bfec0283ad38ae09d4b01a5f5b4dfd359ea Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Tue, 4 Apr 2000 19:57:23 +0000
Subject: [PATCH] Fixed file descriptor leaks.

---
 dlls/x11drv/x11drv_main.c | 2 ++
 files/file.c              | 9 +--------
 scheduler/client.c        | 2 +-
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c
index 7b5ea3acd1d..d546aa86aa5 100644
--- a/dlls/x11drv/x11drv_main.c
+++ b/dlls/x11drv/x11drv_main.c
@@ -5,6 +5,7 @@
  * Copyright 2000 Alexandre Julliard
  */
 
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <X11/cursorfont.h>
@@ -169,6 +170,7 @@ static void process_attach(void)
                  argv0, Options.display ? Options.display : "(none specified)" );
         ExitProcess(1);
     }
+    fcntl( ConnectionNumber(display), F_SETFD, 1 ); /* set close on exec flag */
     screen = DefaultScreenOfDisplay( display );
     visual = DefaultVisual( display, DefaultScreen(display) );
     root_window = DefaultRootWindow( display );
diff --git a/files/file.c b/files/file.c
index 85bdb417409..f10a9bdd79c 100644
--- a/files/file.c
+++ b/files/file.c
@@ -309,16 +309,9 @@ void FILE_SetDosError(void)
  */
 HFILE FILE_DupUnixHandle( int fd, DWORD access )
 {
-    int unix_handle;
     struct alloc_file_handle_request *req = get_req_buffer();
-
-    if ((unix_handle = dup(fd)) == -1)
-    {
-        FILE_SetDosError();
-        return INVALID_HANDLE_VALUE;
-    }
     req->access  = access;
-    server_call_fd( REQ_ALLOC_FILE_HANDLE, unix_handle, NULL );
+    server_call_fd( REQ_ALLOC_FILE_HANDLE, fd, NULL );
     return req->handle;
 }
 
diff --git a/scheduler/client.c b/scheduler/client.c
index f148f53300f..3a997810745 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -390,7 +390,7 @@ int CLIENT_InitServer(void)
     if ((env_fd = getenv( "__WINE_FD" )) && isdigit(env_fd[0]))
     {
         fd = atoi( env_fd );
-        if (fcntl( fd, F_GETFL, 0 ) != -1) return fd;
+        if (fcntl( fd, F_SETFD, 1 ) != -1) return fd; /* set close on exec flag */
     }
 
     /* retrieve the current directory */
-- 
GitLab