Windows GetBasePath: fixed reallocation code.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 28 May 2015 15:32:45 -0400
changeset 9676edd750fa709c
parent 9675 3c7288eb4ca4
child 9677 8201e3e3d026
Windows GetBasePath: fixed reallocation code.
src/filesystem/windows/SDL_sysfilesystem.c
     1.1 --- a/src/filesystem/windows/SDL_sysfilesystem.c	Thu May 28 15:29:43 2015 -0400
     1.2 +++ b/src/filesystem/windows/SDL_sysfilesystem.c	Thu May 28 15:32:45 2015 -0400
     1.3 @@ -58,12 +58,14 @@
     1.4      }
     1.5  
     1.6      while (SDL_TRUE) {
     1.7 -        path = (WCHAR *)SDL_realloc(path, buflen * sizeof (WCHAR));
     1.8 -        if (!path) {
     1.9 +        WCHAR *ptr = (WCHAR *)SDL_realloc(path, buflen * sizeof (WCHAR));
    1.10 +        if (!ptr) {
    1.11 +            SDL_free(path);
    1.12              FreeLibrary(psapi);
    1.13              SDL_OutOfMemory();
    1.14              return NULL;
    1.15          }
    1.16 +        path = ptr;
    1.17  
    1.18          len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen);
    1.19          if (len != buflen) {
    1.20 @@ -71,7 +73,6 @@
    1.21          }
    1.22  
    1.23          /* buffer too small? Try again. */
    1.24 -        SDL_free(path);
    1.25          buflen *= 2;
    1.26      }
    1.27