From 78824ea310d825225c70d4e7fc3f022a2148b785 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 20 Oct 2018 21:00:02 +0300 Subject: [PATCH] timidity: fix potential memory leak in Timidity_LoadSong() --- timidity/timidity.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/timidity/timidity.c b/timidity/timidity.c index 5cf5c9a0..6251f879 100644 --- a/timidity/timidity.c +++ b/timidity/timidity.c @@ -459,9 +459,11 @@ MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio) if (rw == NULL) return NULL; - + /* Allocate memory for the song */ song = (MidiSong *)safe_malloc(sizeof(*song)); + if (song == NULL) + return NULL; memset(song, 0, sizeof(*song)); for (i = 0; i < MAXBANK; i++) @@ -498,6 +500,7 @@ MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio) song->encoding |= PE_MONO; else if (audio->channels > 2) { SDL_SetError("Surround sound not supported"); + free(song); return NULL; } switch (audio->format) { @@ -530,7 +533,8 @@ MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio) break; default: SDL_SetError("Unsupported audio format"); - return NULL; + free(song); + return NULL; } song->buffer_size = audio->samples;