Fixed three memory leaks on failed allocation.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 08 Feb 2015 21:25:37 +0100
changeset 93345eb5ab33286e
parent 9333 de02c2d8a06f
child 9335 3eb0896ecb91
Fixed three memory leaks on failed allocation.
src/events/SDL_mouse.c
src/render/opengl/SDL_render_gl.c
src/video/SDL_bmp.c
     1.1 --- a/src/events/SDL_mouse.c	Sat Feb 07 22:40:36 2015 +0100
     1.2 +++ b/src/events/SDL_mouse.c	Sun Feb 08 21:25:37 2015 +0100
     1.3 @@ -303,10 +303,11 @@
     1.4  {
     1.5      if (button >= mouse->num_clickstates) {
     1.6          int i, count = button + 1;
     1.7 -        mouse->clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
     1.8 -        if (!mouse->clickstate) {
     1.9 +        SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
    1.10 +        if (!clickstate) {
    1.11              return NULL;
    1.12          }
    1.13 +        mouse->clickstate = clickstate;
    1.14  
    1.15          for (i = mouse->num_clickstates; i < count; ++i) {
    1.16              SDL_zero(mouse->clickstate[i]);
     2.1 --- a/src/render/opengl/SDL_render_gl.c	Sat Feb 07 22:40:36 2015 +0100
     2.2 +++ b/src/render/opengl/SDL_render_gl.c	Sun Feb 08 21:25:37 2015 +0100
     2.3 @@ -342,9 +342,10 @@
     2.4  
     2.5      if (type == GL_DEBUG_TYPE_ERROR_ARB) {
     2.6          /* Record this error */
     2.7 +        char **error_messages = SDL_realloc(data->error_messages, data->errors * sizeof(*data->error_messages));
     2.8          ++data->errors;
     2.9 -        data->error_messages = SDL_realloc(data->error_messages, data->errors * sizeof(*data->error_messages));
    2.10 -        if (data->error_messages) {
    2.11 +        if (error_messages) {
    2.12 +            data->error_messages = error_messages;
    2.13              data->error_messages[data->errors-1] = SDL_strdup(message);
    2.14          }
    2.15      }
     3.1 --- a/src/video/SDL_bmp.c	Sat Feb 07 22:40:36 2015 +0100
     3.2 +++ b/src/video/SDL_bmp.c	Sun Feb 08 21:25:37 2015 +0100
     3.3 @@ -306,16 +306,18 @@
     3.4              biClrUsed = 1 << biBitCount;
     3.5          }
     3.6          if ((int) biClrUsed > palette->ncolors) {
     3.7 +            SDL_Color *colors;
     3.8              palette->ncolors = biClrUsed;
     3.9 -            palette->colors =
    3.10 +            colors =
    3.11                  (SDL_Color *) SDL_realloc(palette->colors,
    3.12                                            palette->ncolors *
    3.13                                            sizeof(*palette->colors));
    3.14 -            if (!palette->colors) {
    3.15 +            if (!colors) {
    3.16                  SDL_OutOfMemory();
    3.17                  was_error = SDL_TRUE;
    3.18                  goto done;
    3.19              }
    3.20 +            palette->colors = colors;
    3.21          } else if ((int) biClrUsed < palette->ncolors) {
    3.22              palette->ncolors = biClrUsed;
    3.23          }