Fixed three memory leaks on failed allocation.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 08 Feb 2015 21:25:37 +0100
changeset 9334 5eb5ab33286e
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
--- a/src/events/SDL_mouse.c	Sat Feb 07 22:40:36 2015 +0100
+++ b/src/events/SDL_mouse.c	Sun Feb 08 21:25:37 2015 +0100
@@ -303,10 +303,11 @@
 {
     if (button >= mouse->num_clickstates) {
         int i, count = button + 1;
-        mouse->clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
-        if (!mouse->clickstate) {
+        SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
+        if (!clickstate) {
             return NULL;
         }
+        mouse->clickstate = clickstate;
 
         for (i = mouse->num_clickstates; i < count; ++i) {
             SDL_zero(mouse->clickstate[i]);
--- a/src/render/opengl/SDL_render_gl.c	Sat Feb 07 22:40:36 2015 +0100
+++ b/src/render/opengl/SDL_render_gl.c	Sun Feb 08 21:25:37 2015 +0100
@@ -342,9 +342,10 @@
 
     if (type == GL_DEBUG_TYPE_ERROR_ARB) {
         /* Record this error */
+        char **error_messages = SDL_realloc(data->error_messages, data->errors * sizeof(*data->error_messages));
         ++data->errors;
-        data->error_messages = SDL_realloc(data->error_messages, data->errors * sizeof(*data->error_messages));
-        if (data->error_messages) {
+        if (error_messages) {
+            data->error_messages = error_messages;
             data->error_messages[data->errors-1] = SDL_strdup(message);
         }
     }
--- a/src/video/SDL_bmp.c	Sat Feb 07 22:40:36 2015 +0100
+++ b/src/video/SDL_bmp.c	Sun Feb 08 21:25:37 2015 +0100
@@ -306,16 +306,18 @@
             biClrUsed = 1 << biBitCount;
         }
         if ((int) biClrUsed > palette->ncolors) {
+            SDL_Color *colors;
             palette->ncolors = biClrUsed;
-            palette->colors =
+            colors =
                 (SDL_Color *) SDL_realloc(palette->colors,
                                           palette->ncolors *
                                           sizeof(*palette->colors));
-            if (!palette->colors) {
+            if (!colors) {
                 SDL_OutOfMemory();
                 was_error = SDL_TRUE;
                 goto done;
             }
+            palette->colors = colors;
         } else if ((int) biClrUsed < palette->ncolors) {
             palette->ncolors = biClrUsed;
         }