timidity: fix potential memory leak in Timidity_LoadSong()
authorOzkan Sezer <sezeroz@gmail.com>
Sat, 20 Oct 2018 21:00:02 +0300
changeset 913270f416f3a4f
parent 912 eafae213d7a2
child 914 121b1e9b5684
timidity: fix potential memory leak in Timidity_LoadSong()
timidity/timidity.c
     1.1 --- a/timidity/timidity.c	Thu Oct 18 11:57:16 2018 +0300
     1.2 +++ b/timidity/timidity.c	Sat Oct 20 21:00:02 2018 +0300
     1.3 @@ -459,9 +459,11 @@
     1.4  
     1.5    if (rw == NULL)
     1.6        return NULL;
     1.7 -  
     1.8 +
     1.9    /* Allocate memory for the song */
    1.10    song = (MidiSong *)safe_malloc(sizeof(*song));
    1.11 +  if (song == NULL)
    1.12 +      return NULL;
    1.13    memset(song, 0, sizeof(*song));
    1.14  
    1.15    for (i = 0; i < MAXBANK; i++)
    1.16 @@ -498,6 +500,7 @@
    1.17        song->encoding |= PE_MONO;
    1.18    else if (audio->channels > 2) {
    1.19        SDL_SetError("Surround sound not supported");
    1.20 +      free(song);
    1.21        return NULL;
    1.22    }
    1.23    switch (audio->format) {
    1.24 @@ -530,7 +533,8 @@
    1.25  	  break;
    1.26    default:
    1.27  	  SDL_SetError("Unsupported audio format");
    1.28 -      return NULL;
    1.29 +	  free(song);
    1.30 +	  return NULL;
    1.31    }
    1.32  
    1.33    song->buffer_size = audio->samples;