At the time the "unlink post" hook is fired, the stream is not any more connected to its old device, so it makes sense to reset the sink/source pointer to NULL before firing the hook. If this is not done, the pointer may become stale during the "unlink post" hook, because module-bluetooth-policy does a card profile change in its "unlink post" callback, so even if the pointer is valid when module-bluetooth-policy's callback is called, it will be invalid in subsequent callbacks. --- src/pulsecore/sink-input.c | 10 +++++----- src/pulsecore/source-output.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index 0dda204..c248cd8 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -697,11 +697,6 @@ void pa_sink_input_unlink(pa_sink_input *i) { reset_callbacks(i); - if (linked) { - pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_REMOVE, i->index); - pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], i); - } - if (i->sink) { if (PA_SINK_IS_LINKED(pa_sink_get_state(i->sink))) pa_sink_update_status(i->sink); @@ -709,6 +704,11 @@ void pa_sink_input_unlink(pa_sink_input *i) { i->sink = NULL; } + if (linked) { + pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_REMOVE, i->index); + pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], i); + } + pa_core_maybe_vacuum(i->core); pa_sink_input_unref(i); diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c index 35ef1c5..3c421ad 100644 --- a/src/pulsecore/source-output.c +++ b/src/pulsecore/source-output.c @@ -591,11 +591,6 @@ void pa_source_output_unlink(pa_source_output*o) { reset_callbacks(o); - if (linked) { - pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_REMOVE, o->index); - pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], o); - } - if (o->source) { if (PA_SOURCE_IS_LINKED(pa_source_get_state(o->source))) pa_source_update_status(o->source); @@ -603,6 +598,11 @@ void pa_source_output_unlink(pa_source_output*o) { o->source = NULL; } + if (linked) { + pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_REMOVE, o->index); + pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], o); + } + pa_core_maybe_vacuum(o->core); pa_source_output_unref(o); -- 2.9.3