From 2a2e6a0c763c452f62140c2bde1f23609b9be87a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 30 Mar 2019 12:33:10 +0100 Subject: fix potential memleak under Windows --- src/libui_sdl/Platform.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/libui_sdl/Platform.cpp') diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index e47b686..7eba035 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -197,7 +197,10 @@ FILE* OpenLocalFile(const char* path, const char* mode) PWSTR appDataPath = NULL; SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath); if (!appDataPath) + { + delete[] emudirpath; return NULL; + } // this will be more than enough WCHAR fatperm[4]; @@ -207,16 +210,16 @@ FILE* OpenLocalFile(const char* path, const char* mode) fatperm[3] = 0; int fnlen = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - if (fnlen < 1) return NULL; + if (fnlen < 1) { delete[] emudirpath; return NULL; } WCHAR* wfileName = new WCHAR[fnlen]; int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, wfileName, fnlen); - if (res != fnlen) { delete[] wfileName; return NULL; } // checkme? + if (res != fnlen) { delete[] wfileName; delete[] emudirpath; return NULL; } // checkme? const WCHAR* appdir = L"\\melonDS\\"; int pos = wcslen(appDataPath); void* ptr = CoTaskMemRealloc(appDataPath, (pos+wcslen(appdir)+fnlen+1)*sizeof(WCHAR)); - if (!ptr) { delete[] wfileName; return NULL; } // oh well + if (!ptr) { delete[] wfileName; delete[] emudirpath; return NULL; } // oh well appDataPath = (PWSTR)ptr; wcscpy(&appDataPath[pos], appdir); pos += wcslen(appdir); -- cgit v1.2.3