Skip to content

Commit

Permalink
timidity: fix potential memory leak in Timidity_LoadSong()
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Oct 20, 2018
1 parent e06c846 commit 78824ea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions timidity/timidity.c
Expand Up @@ -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++)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 78824ea

Please sign in to comment.