Merged memory leak fix from SDL 1.2
authorSam Lantinga <slouken@libsdl.org>
Tue, 10 Jul 2007 16:05:50 +0000
changeset 2164d083a2e4433d
parent 2163 5f96cf74b782
child 2165 c2ffcc627701
Merged memory leak fix from SDL 1.2
src/file/SDL_rwops.c
     1.1 --- a/src/file/SDL_rwops.c	Tue Jul 10 15:51:17 2007 +0000
     1.2 +++ b/src/file/SDL_rwops.c	Tue Jul 10 16:05:50 2007 +0000
     1.3 @@ -57,18 +57,7 @@
     1.4      int a_mode;
     1.5  
     1.6      if (!context)
     1.7 -        return -1;
     1.8 -
     1.9 -    context->hidden.win32io.h = INVALID_HANDLE_VALUE;   /* mark this as unusable */
    1.10 -
    1.11 -    context->hidden.win32io.buffer.data =
    1.12 -        (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    1.13 -    if (!context->hidden.win32io.buffer.data) {
    1.14 -        SDL_OutOfMemory();
    1.15 -        return -1;
    1.16 -    }
    1.17 -    context->hidden.win32io.buffer.size = 0;
    1.18 -    context->hidden.win32io.buffer.left = 0;
    1.19 +        return -1;              /* failed (invalid call) */
    1.20  
    1.21      /* "r" = reading, file must exist */
    1.22      /* "w" = writing, truncate existing, file may not exist */
    1.23 @@ -126,6 +115,16 @@
    1.24      context->hidden.win32io.h = h;
    1.25      context->hidden.win32io.append = a_mode ? SDL_TRUE : SDL_FALSE;
    1.26  
    1.27 +    context->hidden.win32io.buffer.data =
    1.28 +        (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    1.29 +    if (!context->hidden.win32io.buffer.data) {
    1.30 +        SDL_OutOfMemory();
    1.31 +        CloseHandle(context->hidden.win32io.h);
    1.32 +        return -1;
    1.33 +    }
    1.34 +    context->hidden.win32io.buffer.size = 0;
    1.35 +    context->hidden.win32io.buffer.left = 0;
    1.36 +
    1.37      return 0;                   /* ok */
    1.38  }
    1.39  static long SDLCALL
    1.40 @@ -428,8 +427,7 @@
    1.41      rwops = SDL_AllocRW();
    1.42      if (!rwops)
    1.43          return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
    1.44 -    rwops->hidden.win32io.h = INVALID_HANDLE_VALUE;
    1.45 -    if (win32_file_open(rwops, file, mode)) {
    1.46 +    if (win32_file_open(rwops, file, mode) < 0) {
    1.47          SDL_FreeRW(rwops);
    1.48          return NULL;
    1.49      }