mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-11-27 06:22:06 +00:00
Fix order of object creation in fluidsynth binary
Fixes a use-after-free when the MIDI player is deleted before the audio driver, because the synthesis thread is still actively making callbacks on the sample timer, which is deleted by the player though.
This commit is contained in:
parent
686556decc
commit
6d8f338d42
1 changed files with 31 additions and 53 deletions
|
@ -777,18 +777,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/* start the synthesis thread */
|
||||
if(!fast_render)
|
||||
{
|
||||
adriver = new_fluid_audio_driver(settings, synth);
|
||||
|
||||
if(adriver == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to create the audio driver\n");
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
router = new_fluid_midi_router(
|
||||
settings,
|
||||
dump ? fluid_midi_dump_postrouter : fluid_synth_handle_midi_event,
|
||||
|
@ -926,21 +914,6 @@ int main(int argc, char **argv)
|
|||
|
||||
#endif
|
||||
|
||||
/* run the shell */
|
||||
if(interactive)
|
||||
{
|
||||
printf("Type 'help' for help topics.\n\n");
|
||||
|
||||
/* In dump mode we set the prompt to "". The UI cannot easily
|
||||
* handle lines, which don't end with CR. Changing the prompt
|
||||
* cannot be done through a command, because the current shell
|
||||
* does not handle empty arguments. The ordinary case is dump ==
|
||||
* 0.
|
||||
*/
|
||||
fluid_settings_setstr(settings, "shell.prompt", dump ? "" : "> ");
|
||||
fluid_usershell(settings, cmd_handler); /* this is a synchronous shell */
|
||||
}
|
||||
|
||||
/* fast rendering audio file, if requested */
|
||||
if(fast_render)
|
||||
{
|
||||
|
@ -962,6 +935,31 @@ int main(int argc, char **argv)
|
|||
|
||||
fast_render_loop(settings, synth, player);
|
||||
}
|
||||
else /* start the synthesis thread */
|
||||
{
|
||||
adriver = new_fluid_audio_driver(settings, synth);
|
||||
|
||||
if(adriver == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to create the audio driver\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* run the shell */
|
||||
if(interactive)
|
||||
{
|
||||
printf("Type 'help' for help topics.\n\n");
|
||||
|
||||
/* In dump mode we set the prompt to "". The UI cannot easily
|
||||
* handle lines, which don't end with CR. Changing the prompt
|
||||
* cannot be done through a command, because the current shell
|
||||
* does not handle empty arguments. The ordinary case is dump ==
|
||||
* 0.
|
||||
*/
|
||||
fluid_settings_setstr(settings, "shell.prompt", dump ? "" : "> ");
|
||||
fluid_usershell(settings, cmd_handler); /* this is a synchronous shell */
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
|
@ -1003,34 +1001,14 @@ cleanup:
|
|||
/* if no audio driver and sample timers are used, nothing makes the player advance */
|
||||
fluid_player_join(player);
|
||||
}
|
||||
|
||||
delete_fluid_player(player);
|
||||
}
|
||||
|
||||
if(mdriver)
|
||||
{
|
||||
delete_fluid_midi_driver(mdriver);
|
||||
}
|
||||
|
||||
if(router)
|
||||
{
|
||||
delete_fluid_midi_router(router);
|
||||
}
|
||||
|
||||
if(adriver)
|
||||
{
|
||||
delete_fluid_audio_driver(adriver);
|
||||
}
|
||||
|
||||
if(synth)
|
||||
{
|
||||
delete_fluid_synth(synth);
|
||||
}
|
||||
|
||||
if(settings)
|
||||
{
|
||||
delete_fluid_settings(settings);
|
||||
}
|
||||
delete_fluid_audio_driver(adriver);
|
||||
delete_fluid_player(player);
|
||||
delete_fluid_midi_driver(mdriver);
|
||||
delete_fluid_midi_router(router);
|
||||
delete_fluid_synth(synth);
|
||||
delete_fluid_settings(settings);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue