From aa43bee434e1e69b937cdc46edc70aabbf1e7cae Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 28 May 2015 15:32:45 -0400 Subject: [PATCH] Windows GetBasePath: fixed reallocation code. --- src/filesystem/windows/SDL_sysfilesystem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c index 381b2d1d8..2bc799226 100644 --- a/src/filesystem/windows/SDL_sysfilesystem.c +++ b/src/filesystem/windows/SDL_sysfilesystem.c @@ -58,12 +58,14 @@ SDL_GetBasePath(void) } while (SDL_TRUE) { - path = (WCHAR *)SDL_realloc(path, buflen * sizeof (WCHAR)); - if (!path) { + WCHAR *ptr = (WCHAR *)SDL_realloc(path, buflen * sizeof (WCHAR)); + if (!ptr) { + SDL_free(path); FreeLibrary(psapi); SDL_OutOfMemory(); return NULL; } + path = ptr; len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen); if (len != buflen) { @@ -71,7 +73,6 @@ SDL_GetBasePath(void) } /* buffer too small? Try again. */ - SDL_free(path); buflen *= 2; }