瀏覽代碼

Windows GetBasePath: fixed reallocation code.

Ryan C. Gordon 10 年之前
父節點
當前提交
aa43bee434
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      src/filesystem/windows/SDL_sysfilesystem.c

+ 4 - 3
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;
     }