From d19395459f34310c59ddacdd9cdfb78efd169259 Mon Sep 17 00:00:00 2001 From: hvlad Date: Sun, 14 Feb 2010 12:18:07 +0000 Subject: [PATCH] Fixed bug CORE-2864 : Listener process of Classic Server leak handles. --- src/remote/inet.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/remote/inet.cpp b/src/remote/inet.cpp index 5aad712124..1a3305b197 100644 --- a/src/remote/inet.cpp +++ b/src/remote/inet.cpp @@ -1631,7 +1631,7 @@ static void wsaExitHandler(void*) } -static int fork(SOCKET handle, USHORT flag) +static int fork(SOCKET old_handle, USHORT flag) { /************************************** * @@ -1646,8 +1646,17 @@ static int fork(SOCKET handle, USHORT flag) TEXT name[MAXPATHLEN]; GetModuleFileName(NULL, name, sizeof(name)); + HANDLE new_handle; + if (!DuplicateHandle(GetCurrentProcess(), (HANDLE) old_handle, + GetCurrentProcess(), &new_handle, + 0, TRUE, DUPLICATE_SAME_ACCESS)) + { + gds__log("INET/inet_error: fork/DuplicateHandle errno = %d", GetLastError()); + return 0; + } + Firebird::string cmdLine; - cmdLine.printf("%s -i -h %"HANDLEFORMAT"@%"ULONGFORMAT, name, handle, GetCurrentProcessId()); + cmdLine.printf("%s -i -h %"HANDLEFORMAT"@%"ULONGFORMAT, name, new_handle, GetCurrentProcessId()); STARTUPINFO start_crud; start_crud.cb = sizeof(STARTUPINFO); @@ -1672,7 +1681,7 @@ static int fork(SOCKET handle, USHORT flag) } gds__log("INET/inet_error: fork/CreateProcess errno = %d", GetLastError()); - SOCLOSE(handle); + CloseHandle(new_handle); return 0; } @@ -1699,6 +1708,7 @@ THREAD_ENTRY_DECLARE forkThread(THREAD_ENTRY_PARAM arg) forkSockets->remove((size_t) 0); } fork(s, flag); + SOCLOSE(s); } }