Fixed three memory leaks on failed allocation.

This commit is contained in:
Philipp Wiesemann 2015-02-08 21:25:37 +01:00
parent c17a5b1177
commit fe586d077f
3 changed files with 10 additions and 6 deletions

View File

@ -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]);

View File

@ -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);
}
}

View File

@ -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;
}