Windows GetBasePath: fixed reallocation code.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 28 May 2015 15:32:45 -0400
changeset 9676 edd750fa709c
parent 9675 3c7288eb4ca4
child 9677 8201e3e3d026
Windows GetBasePath: fixed reallocation code.
src/filesystem/windows/SDL_sysfilesystem.c
--- a/src/filesystem/windows/SDL_sysfilesystem.c	Thu May 28 15:29:43 2015 -0400
+++ b/src/filesystem/windows/SDL_sysfilesystem.c	Thu May 28 15:32:45 2015 -0400
@@ -58,12 +58,14 @@
     }
 
     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 @@
         }
 
         /* buffer too small? Try again. */
-        SDL_free(path);
         buflen *= 2;
     }