diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 08766c42..57d16254 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -489,13 +489,13 @@ void fluid_sample_timer_process(fluid_synth_t* synth) unsigned int ticks = fluid_synth_get_ticks(synth); for (st=synth->sample_timers; st; st=stnext) { + /* st may be freed in the callback below. cache it's successor now to avoid use after free */ + stnext = st->next; + if (st->isfinished) { continue; } - msec = (long) (1000.0*((double) (ticks - st->starttick))/synth->sample_rate); - /* st may be freed in the callback below. cache it's successor now to avoid use after free */ - stnext = st->next; cont = (*st->callback)(st->data, msec); if (cont == 0) { st->isfinished = 1;