changeset 2164:d083a2e4433d

Merged memory leak fix from SDL 1.2
author Sam Lantinga <slouken@libsdl.org>
date Tue, 10 Jul 2007 16:05:50 +0000
parents 5f96cf74b782
children c2ffcc627701
files src/file/SDL_rwops.c
diffstat 1 files changed, 12 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/file/SDL_rwops.c	Tue Jul 10 15:51:17 2007 +0000
+++ b/src/file/SDL_rwops.c	Tue Jul 10 16:05:50 2007 +0000
@@ -57,18 +57,7 @@
     int a_mode;
 
     if (!context)
-        return -1;
-
-    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;
+        return -1;              /* failed (invalid call) */
 
     /* "r" = reading, file must exist */
     /* "w" = writing, truncate existing, file may not exist */
@@ -126,6 +115,16 @@
     context->hidden.win32io.h = h;
     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 */
 }
 static long SDLCALL
@@ -428,8 +427,7 @@
     rwops = SDL_AllocRW();
     if (!rwops)
         return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
-    rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
-    if (win32_file_open(rwops, file, mode)) {
+    if (win32_file_open(rwops, file, mode) < 0) {
         SDL_FreeRW(rwops);
         return NULL;
     }