native_midi_common.c: backport two fixes from default (2.0) branch. SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sun, 07 Oct 2018 00:42:10 +0300
branchSDL-1.2
changeset 875f067e333302e
parent 874 6a0b7356d763
child 876 fab846266822
native_midi_common.c: backport two fixes from default (2.0) branch.
native_midi/native_midi_common.c
     1.1 --- a/native_midi/native_midi_common.c	Sun Oct 07 00:29:50 2018 +0300
     1.2 +++ b/native_midi/native_midi_common.c	Sun Oct 07 00:42:10 2018 +0300
     1.3 @@ -226,13 +226,15 @@
     1.4  	MIDIEvent *currentEvent = head;
     1.5  	int trackID;
     1.6  
     1.7 -    if (NULL == head)
     1.8 +	if (NULL == head)
     1.9  		return NULL;
    1.10 -        
    1.11 -    track = (MIDIEvent**) calloc(1, sizeof(MIDIEvent*) * mididata->nTracks);
    1.12 -	if (NULL == head)
    1.13 -        return NULL;
    1.14 -	
    1.15 +
    1.16 +	track = (MIDIEvent**) calloc(1, sizeof(MIDIEvent*) * mididata->nTracks);
    1.17 +	if (NULL == track)
    1.18 +	{
    1.19 +		free(head);
    1.20 +		return NULL;
    1.21 +	}
    1.22  	/* First, convert all tracks to MIDIEvent lists */
    1.23  	for (trackID = 0; trackID < mididata->nTracks; trackID++)
    1.24  		track[trackID] = MIDITracktoStream(&mididata->track[trackID]);
    1.25 @@ -380,14 +382,18 @@
    1.26  		*division = mididata->division;
    1.27  	
    1.28  	eventList = MIDItoStream(mididata);
    1.29 -	
    1.30 +	if (eventList == NULL)
    1.31 +	{
    1.32 +		free(mididata);
    1.33 +		return NULL;
    1.34 +	}
    1.35  	for(trackID = 0; trackID < mididata->nTracks; trackID++)
    1.36  	{
    1.37  		if (mididata->track[trackID].data)
    1.38  			free(mididata->track[trackID].data);
    1.39  	}
    1.40  	free(mididata->track);
    1.41 -    free(mididata);
    1.42 +	free(mididata);
    1.43  	
    1.44  	return eventList;
    1.45  }