From 99f55f32e345e44eb8c82deb4bfcfb669e728ff6 Mon Sep 17 00:00:00 2001 From: Kamil Monicz Date: Sun, 22 Nov 2026 20:57:53 +0100 Subject: [PATCH] Close only valid Windows directory search handles Supersedes #267. An unopened entry holds NULL; a failed FindFirstFile leaves INVALID_HANDLE_VALUE. Skip FindClose in both cases. --- nob.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nob.h b/nob.h index 8c01658..924debb 100644 --- a/nob.h +++ b/nob.h @@ -2104,7 +2104,8 @@ NOBDEF bool nob_dir_entry_next(Nob_Dir_Entry *dir) NOBDEF void nob_dir_entry_close(Nob_Dir_Entry dir) { #ifdef _WIN32 - FindClose(dir.nob__private.win32_hFind); + HANDLE h = dir.nob__private.win32_hFind; + if (h != NULL && h != INVALID_HANDLE_VALUE) FindClose(h); #else if (dir.nob__private.posix_dir) closedir(dir.nob__private.posix_dir); #endif