From e65afe8fa2e83ac21b8cbe7481a2ab6c55986336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 4 Jun 2021 02:26:17 +0200 Subject: [PATCH] pulse-server: module-combine-sink: remove hooks Remove hooks when the module is unloaded to avoid use-after-free issues. Remove the cleanup source as well. Fixes #1259. --- .../modules/module-combine-sink.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/module-protocol-pulse/modules/module-combine-sink.c b/src/modules/module-protocol-pulse/modules/module-combine-sink.c index 0e8b3aefb..e2399a5a4 100644 --- a/src/modules/module-protocol-pulse/modules/module-combine-sink.c +++ b/src/modules/module-protocol-pulse/modules/module-combine-sink.c @@ -284,8 +284,11 @@ static const struct pw_manager_events manager_events = { .added = manager_added, }; -static void cleanup_stream(struct combine_stream *s) { +static void cleanup_stream(struct combine_stream *s) +{ + spa_hook_remove(&s->stream_listener); pw_stream_destroy(s->stream); + s->stream = NULL; s->data = NULL; s->cleanup = false; @@ -370,20 +373,31 @@ static int module_combine_sink_unload(struct client *client, struct module *modu pw_log_info("unload module %p id:%u name:%s", module, module->idx, module->name); + if (d->cleanup != NULL) + pw_loop_destroy_source(module->impl->loop, d->cleanup); + /* Note that we explicitly disconnect the hooks to avoid having the * cleanup triggered again in those callbacks */ if (d->sink != NULL) { spa_hook_remove(&d->sink_listener); pw_stream_destroy(d->sink); } + for (i = 0; i < MAX_SINKS; i++) { if (d->streams[i].stream) cleanup_stream(&d->streams[i]); } - if (d->manager != NULL) + + if (d->manager != NULL) { + spa_hook_remove(&d->manager_listener); pw_manager_destroy(d->manager); - if (d->core != NULL) + } + + if (d->core != NULL) { + spa_hook_remove(&d->core_listener); pw_core_disconnect(d->core); + } + pw_free_strv(d->sink_names); free(d->sink_name);