Skip to content

Commit e63201b

Browse files
committed
timidity: fix potential memory leak in Timidity_LoadSong()
1 parent 9529542 commit e63201b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

timidity/timidity.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,11 @@ MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio)
459459

460460
if (rw == NULL)
461461
return NULL;
462-
462+
463463
/* Allocate memory for the song */
464464
song = (MidiSong *)safe_malloc(sizeof(*song));
465+
if (song == NULL)
466+
return NULL;
465467
memset(song, 0, sizeof(*song));
466468

467469
for (i = 0; i < MAXBANK; i++)
@@ -498,6 +500,7 @@ MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio)
498500
song->encoding |= PE_MONO;
499501
else if (audio->channels > 2) {
500502
SDL_SetError("Surround sound not supported");
503+
free(song);
501504
return NULL;
502505
}
503506
switch (audio->format) {
@@ -530,7 +533,8 @@ MidiSong *Timidity_LoadSong(SDL_RWops *rw, SDL_AudioSpec *audio)
530533
break;
531534
default:
532535
SDL_SetError("Unsupported audio format");
533-
return NULL;
536+
free(song);
537+
return NULL;
534538
}
535539

536540
song->buffer_size = audio->samples;

0 commit comments

Comments
 (0)