From 4d1626d042a464da9fa64e5b1caa7a69ae9775b2 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 28 May 2015 15:36:27 -0400 Subject: [PATCH] Windows SDL_GetBasePath: free string on failure. --- src/filesystem/windows/SDL_sysfilesystem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c index 2bc799226..2d1c78198 100644 --- a/src/filesystem/windows/SDL_sysfilesystem.c +++ b/src/filesystem/windows/SDL_sysfilesystem.c @@ -58,14 +58,15 @@ SDL_GetBasePath(void) } while (SDL_TRUE) { - WCHAR *ptr = (WCHAR *)SDL_realloc(path, buflen * sizeof (WCHAR)); + void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR)); if (!ptr) { SDL_free(path); FreeLibrary(psapi); SDL_OutOfMemory(); return NULL; } - path = ptr; + + path = (WCHAR *) ptr; len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen); if (len != buflen) { @@ -79,6 +80,7 @@ SDL_GetBasePath(void) FreeLibrary(psapi); if (len == 0) { + SDL_free(path); WIN_SetError("Couldn't locate our .exe"); return NULL; }