Skip to content

Commit

Permalink
Remove audio source callbacks in filter_remove
Browse files Browse the repository at this point in the history
obs_weak_source_get_source was returning NULL in destroy, which meant
that the signal handler could not be disconnected. As a result the audio
source destroy callback was called after the filter's destruction,
resulting in use after free
See #6
  • Loading branch information
dimtpap committed Apr 1, 2024
1 parent 79906e0 commit 2c0e459
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/scale-to-sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,34 @@ static void scale_to_sound_defaults(obs_data_t *settings)
obs_data_set_default_int(settings, STS_YPOSAL, CENTER);
}

static void scale_to_sound_destroy(void *data)
static void scale_to_sound_remove(void *data, obs_source_t *source)
{
UNUSED_PARAMETER(source);

struct scale_to_sound_data *stsf = data;

if (stsf->audio_source) {
obs_source_t *current_target = obs_weak_source_get_source(stsf->audio_source);

if (!current_target) {
return;
}

signal_handler_t *sig_handler = obs_source_get_signal_handler(current_target);
signal_handler_disconnect(sig_handler, "destroy", audio_source_destroy, stsf);

obs_source_remove_audio_capture_callback(current_target, audio_source_capture_callback, stsf);

obs_source_release(current_target);
obs_weak_source_release(stsf->audio_source);

stsf->audio_source = NULL;
}
}

static void scale_to_sound_destroy(void *data)
{
struct scale_to_sound_data *stsf = data;

obs_enter_graphics();
gs_effect_destroy(stsf->mover);
Expand Down Expand Up @@ -482,6 +495,7 @@ const struct obs_source_info scale_to_sound = {
.update = scale_to_sound_update,
.video_tick = scale_to_sound_tick,
.video_render = scale_to_sound_render,
.filter_remove = scale_to_sound_remove,
.destroy = scale_to_sound_destroy,
};

Expand Down

0 comments on commit 2c0e459

Please sign in to comment.