From ca9c67353f08bc2e54a6492c8fffb097305e6a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 13 Mar 2026 10:58:38 +0800 Subject: [PATCH] Global (Windows): prefers `NtClose` over `CloseHandle` --- src/common/impl/io_windows.c | 6 +++--- src/common/impl/processing_windows.c | 4 ++-- src/common/io.h | 2 +- src/common/thread.h | 8 ++++---- src/detection/bluetoothradio/bluetoothradio_windows.c | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/common/impl/io_windows.c b/src/common/impl/io_windows.c index d2b5018b1..7e04ca86c 100644 --- a/src/common/impl/io_windows.c +++ b/src/common/impl/io_windows.c @@ -128,12 +128,12 @@ static bool createSubfolders(wchar_t* fileName) if (!NT_SUCCESS(status)) { if (closeRoot && hRoot != INVALID_HANDLE_VALUE) - CloseHandle(hRoot); + NtClose(hRoot); return false; } if (closeRoot && hRoot != INVALID_HANDLE_VALUE) - CloseHandle(hRoot); + NtClose(hRoot); hRoot = hNew; closeRoot = true; @@ -141,7 +141,7 @@ static bool createSubfolders(wchar_t* fileName) } if (closeRoot && hRoot != INVALID_HANDLE_VALUE) - CloseHandle(hRoot); + NtClose(hRoot); return true; } diff --git a/src/common/impl/processing_windows.c b/src/common/impl/processing_windows.c index c78cc4a47..1098c6ab7 100644 --- a/src/common/impl/processing_windows.c +++ b/src/common/impl/processing_windows.c @@ -116,7 +116,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle* &piProcInfo // receives PROCESS_INFORMATION ); - CloseHandle(hChildPipeWrite); + NtClose(hChildPipeWrite); if(!success) { if (GetLastError() == ERROR_FILE_NOT_FOUND) @@ -124,7 +124,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle* return "CreateProcessA() failed"; } - CloseHandle(piProcInfo.hThread); // we don't need the thread handle + NtClose(piProcInfo.hThread); // we don't need the thread handle outHandle->pid = piProcInfo.hProcess; outHandle->pipeRead = hChildPipeRead; hChildPipeRead = INVALID_HANDLE_VALUE; // ownership transferred, don't close it diff --git a/src/common/io.h b/src/common/io.h index d287f2da9..efbabc37c 100644 --- a/src/common/io.h +++ b/src/common/io.h @@ -204,7 +204,7 @@ static inline bool wrapClose(FFNativeFD* pfd) #ifndef _WIN32 close(*pfd); #else - CloseHandle(*pfd); + NtClose(*pfd); #endif return true; diff --git a/src/common/thread.h b/src/common/thread.h index deb4fba15..c7670452d 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -4,7 +4,7 @@ #ifdef FF_HAVE_THREADS #if defined(_WIN32) - #include + #include #include #include #include @@ -18,16 +18,16 @@ } #define FF_THREAD_ENTRY_DECL_WRAPPER(fn, paramType) static __stdcall unsigned fn ## ThreadMain (void* data) { fn((paramType)data); return 0; } #define FF_THREAD_ENTRY_DECL_WRAPPER_NOPARAM(fn) static __stdcall unsigned fn ## ThreadMain () { fn(); return 0; } - static inline void ffThreadDetach(FFThreadType thread) { CloseHandle(thread); } + static inline void ffThreadDetach(FFThreadType thread) { NtClose(thread); } static inline bool ffThreadJoin(FFThreadType thread, uint32_t timeout) { if (WaitForSingleObject(thread, timeout == 0 ? (DWORD) -1 : timeout) != 0 /*WAIT_OBJECT_0*/) { TerminateThread(thread, (DWORD) -1); - CloseHandle(thread); + NtClose(thread); return false; } - CloseHandle(thread); + NtClose(thread); return true; } #else diff --git a/src/detection/bluetoothradio/bluetoothradio_windows.c b/src/detection/bluetoothradio/bluetoothradio_windows.c index c725b24ac..3d3d27c87 100644 --- a/src/detection/bluetoothradio/bluetoothradio_windows.c +++ b/src/detection/bluetoothradio/bluetoothradio_windows.c @@ -98,7 +98,7 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */) device->connectable = ffBluetoothIsConnectable(hRadio); device->discoverable = ffBluetoothIsDiscoverable(hRadio); - CloseHandle(hRadio); + NtClose(hRadio); } while (ffBluetoothFindNextRadio(hFind, &hRadio)); ffBluetoothFindRadioClose(hFind);