From 3b2c25d22367dffc019903d6f58567886b99b0c6 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Mon, 14 Feb 2022 12:29:47 -0500 Subject: [PATCH] win,fs: avoid closing an invalid handle (#3473) While usually functional, calling CloseHandle(INVALID_HANDLE_VALUE) can result in debug builds (and/or wine) being unhappy and aborting there. --- src/win/fs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/win/fs.c b/src/win/fs.c index 41aeffddc..a177a73ed 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -1880,8 +1880,9 @@ INLINE static DWORD fs__stat_impl_from_path(WCHAR* path, NULL); if (handle == INVALID_HANDLE_VALUE) - ret = GetLastError(); - else if (fs__stat_handle(handle, statbuf, do_lstat) != 0) + return GetLastError(); + + if (fs__stat_handle(handle, statbuf, do_lstat) != 0) ret = GetLastError(); else ret = 0; @@ -2299,13 +2300,13 @@ INLINE static DWORD fs__utime_impl_from_path(WCHAR* path, flags, NULL); - if (handle == INVALID_HANDLE_VALUE) { + if (handle == INVALID_HANDLE_VALUE) + return GetLastError(); + + if (fs__utime_handle(handle, atime, mtime) != 0) ret = GetLastError(); - } else if (fs__utime_handle(handle, atime, mtime) != 0) { - ret = GetLastError(); - } else { + else ret = 0; - } CloseHandle(handle); return ret;