Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed three memory leaks on failed allocation.
  • Loading branch information
philippwiesemann committed Feb 8, 2015
1 parent c17a5b1 commit fe586d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/events/SDL_mouse.c
Expand Up @@ -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]);
Expand Down
5 changes: 3 additions & 2 deletions src/render/opengl/SDL_render_gl.c
Expand Up @@ -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);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/video/SDL_bmp.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit fe586d0

Please sign in to comment.