Handle OOM in note_on without SEGV
When note_on tries to reallocate the voices[] array, realloc can return NULL. In this case, instead of faulting, restore the original pointer (which is untouched per realloc() semantics) and ignore the note_on command.
This commit is contained in:
1 parent
f7b6f90ffe
commit
545127558f
1 file changed
+6
@@ -1521,7 +1521,13 @@ TSFDEF void tsf_note_on(tsf* f, int preset, int key, float vel)
|
||||
if (!voice)
|
||||
{
|
||||
f->voiceNum += 4;
|
||||
struct tsf_voice *saveVoice = f->voices;
|
||||
f->voices = (struct tsf_voice*)TSF_REALLOC(f->voices, f->voiceNum * sizeof(struct tsf_voice));
|
||||
if (!f->voices) {
|
||||
f->voices = saveVoice;
|
||||
printf("OOM, no room for new voice. Ignoring note_on\n");
|
||||
return;
|
||||
}
|
||||
voice = &f->voices[f->voiceNum - 4];
|
||||
voice[1].playingPreset = voice[2].playingPreset = voice[3].playingPreset = -1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user