Skip to content

Commit

Permalink
Fix heap-use-after free
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Jan 2, 2021
1 parent e594f49 commit 28bd7e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/midi/fluid_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,9 @@ delete_fluid_player(fluid_player_t *player)

fluid_return_if_fail(player != NULL);

fluid_settings_callback_int(player->synth->settings, "player.reset-synth",
NULL, NULL);

fluid_player_stop(player);
fluid_player_reset(player);

Expand Down
44 changes: 44 additions & 0 deletions src/synth/fluid_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,50 @@ delete_fluid_synth(fluid_synth_t *synth)

fluid_profiling_print();

/* unregister all real-time settings callback, to avoid a use-after-free when changing those settings after
* this synth has been deleted*/

fluid_settings_callback_num(synth->settings, "synth.gain",
NULL, NULL);
fluid_settings_callback_int(synth->settings, "synth.polyphony",
NULL, NULL);
fluid_settings_callback_int(synth->settings, "synth.device-id",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.overflow.percussion",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.overflow.sustained",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.overflow.released",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.overflow.age",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.overflow.volume",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.overflow.important",
NULL, NULL);
fluid_settings_callback_str(synth->settings, "synth.overflow.important-channels",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.reverb.room-size",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.reverb.damp",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.reverb.width",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.reverb.level",
NULL, NULL);
fluid_settings_callback_int(synth->settings, "synth.reverb.active",
NULL, NULL);
fluid_settings_callback_int(synth->settings, "synth.chorus.active",
NULL, NULL);
fluid_settings_callback_int(synth->settings, "synth.chorus.nr",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.chorus.level",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.chorus.depth",
NULL, NULL);
fluid_settings_callback_num(synth->settings, "synth.chorus.speed",
NULL, NULL);

/* turn off all voices, needed to unload SoundFont data */
if(synth->voice != NULL)
{
Expand Down

0 comments on commit 28bd7e7

Please sign in to comment.