Fixed three memory leaks on failed allocation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 32eb0f9..0ce443a 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -303,10 +303,11 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
{
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]);
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index ecd0d53..f34bf12 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -342,9 +342,10 @@ GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GL
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);
}
}
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index fcc48c6..c5de8f0 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -306,16 +306,18 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
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;
}