diff options
author | Arisotura <thetotalworm@gmail.com> | 2019-03-30 12:33:10 +0100 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2019-03-30 12:33:10 +0100 |
commit | 2a2e6a0c763c452f62140c2bde1f23609b9be87a (patch) | |
tree | a33bf6b2a1c2469a287a2505257d29a3d4828b3e /src | |
parent | 60a728283eef254c218dc53311c043af2b396d49 (diff) |
fix potential memleak under Windows
Diffstat (limited to 'src')
-rw-r--r-- | src/libui_sdl/Platform.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
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); |