Commit ff88381b authored by Sam Lantinga's avatar Sam Lantinga

Merged memory leak fix from SDL 1.2

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402469
parent 7347a1db
...@@ -57,18 +57,7 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode) ...@@ -57,18 +57,7 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
int a_mode; int a_mode;
if (!context) if (!context)
return -1; return -1; /* failed (invalid call) */
context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
context->hidden.win32io.buffer.data =
(char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.win32io.buffer.data) {
SDL_OutOfMemory();
return -1;
}
context->hidden.win32io.buffer.size = 0;
context->hidden.win32io.buffer.left = 0;
/* "r" = reading, file must exist */ /* "r" = reading, file must exist */
/* "w" = writing, truncate existing, file may not exist */ /* "w" = writing, truncate existing, file may not exist */
...@@ -126,6 +115,16 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode) ...@@ -126,6 +115,16 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode)
context->hidden.win32io.h = h; context->hidden.win32io.h = h;
context->hidden.win32io.append = a_mode ? SDL_TRUE : SDL_FALSE; context->hidden.win32io.append = a_mode ? SDL_TRUE : SDL_FALSE;
context->hidden.win32io.buffer.data =
(char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.win32io.buffer.data) {
SDL_OutOfMemory();
CloseHandle(context->hidden.win32io.h);
return -1;
}
context->hidden.win32io.buffer.size = 0;
context->hidden.win32io.buffer.left = 0;
return 0; /* ok */ return 0; /* ok */
} }
static long SDLCALL static long SDLCALL
...@@ -428,8 +427,7 @@ SDL_RWFromFile(const char *file, const char *mode) ...@@ -428,8 +427,7 @@ SDL_RWFromFile(const char *file, const char *mode)
rwops = SDL_AllocRW(); rwops = SDL_AllocRW();
if (!rwops) if (!rwops)
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
rwops->hidden.win32io.h = INVALID_HANDLE_VALUE; if (win32_file_open(rwops, file, mode) < 0) {
if (win32_file_open(rwops, file, mode)) {
SDL_FreeRW(rwops); SDL_FreeRW(rwops);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment