From 706ce7a6da0f302b56ebbef65f437c66291d738d Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 10 Dec 2023 20:47:32 -0600 Subject: [PATCH] fixed: segmentation fault on windows --- core/os/dir.onyx | 5 ++++- runtime/src/ort_directories.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/os/dir.onyx b/core/os/dir.onyx index 2cd83ed3..697ae315 100644 --- a/core/os/dir.onyx +++ b/core/os/dir.onyx @@ -61,7 +61,10 @@ list_directory :: (path: str) -> Iterator(DirectoryEntry) { } close :: (use c: &Context) { - dir_close(dir); + if opened { + dir_close(dir); + } + cfree(c); } diff --git a/runtime/src/ort_directories.h b/runtime/src/ort_directories.h index a2285246..80c0f261 100644 --- a/runtime/src/ort_directories.h +++ b/runtime/src/ort_directories.h @@ -111,6 +111,7 @@ ONYX_DEF(__dir_read, (WASM_I64, WASM_I32), (WASM_I32)) { ONYX_DEF(__dir_close, (WASM_I64), ()) { #ifdef _BH_WINDOWS Windows_Directory_Opened* dir = (Windows_Directory_Opened *) params->data[0].of.i64; + if (dir == NULL) return NULL; FindClose(dir->hndl); free(dir); -- 2.25.1