From e882e0b1e049c561f5f5d29b16394fb23bfdcfab Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 14 Feb 2022 19:28:23 +0100 Subject: [PATCH] Clear filewrapper info on exit --- src/FileWrapper.cpp | 21 +++++++++++++++++++++ src/FileWrapper.h | 3 ++- src/main.cpp | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/FileWrapper.cpp b/src/FileWrapper.cpp index aeb358c..78eff28 100644 --- a/src/FileWrapper.cpp +++ b/src/FileWrapper.cpp @@ -26,6 +26,27 @@ int FileHandleWrapper_GetSlot() { return res; } +bool FileHandleWrapper_FreeSlot(uint32_t slot) { + if (slot >= FILE_WRAPPER_SIZE) { + return false; + } + OSLockMutex(&fileWrapperMutex); + gFileHandleWrapper[slot].handle = 0; + gFileHandleWrapper[slot].inUse = false; + OSMemoryBarrier(); + OSUnlockMutex(&fileWrapperMutex); + return -1; +} + +bool FileHandleWrapper_FreeAll() { + OSLockMutex(&fileWrapperMutex); + for (int i = 0; i < FILE_WRAPPER_SIZE; i++) { + FileHandleWrapper_FreeSlot(i); + } + OSUnlockMutex(&fileWrapperMutex); + return -1; +} + int OpenFileForID(int id, const char *filepath, int *handle) { if (!mountRomfs(id)) { return -1; diff --git a/src/FileWrapper.h b/src/FileWrapper.h index e2ed8ae..9aa69a2 100644 --- a/src/FileWrapper.h +++ b/src/FileWrapper.h @@ -9,4 +9,5 @@ typedef struct FileHandleWrapper_t { #define FILE_WRAPPER_SIZE 64 extern FileHandleWrapper gFileHandleWrapper[FILE_WRAPPER_SIZE]; -int OpenFileForID(int id, const char *path, int32_t *handle); \ No newline at end of file +int OpenFileForID(int id, const char *path, int32_t *handle); +bool FileHandleWrapper_FreeAll(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 53afac1..6725299 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,6 +72,7 @@ ON_APPLICATION_START() { } ON_APPLICATION_ENDS() { + FileHandleWrapper_FreeAll(); deinitLogging(); }