From 15431570f4398272acff878766b2346cb3625b32 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 6 May 2022 10:14:04 +0200 Subject: [PATCH] module: handle global destroy properly When the global is destroyed, we remove our listeners and set the global to NULL. We then destroy the module but because the global is NULL, we don't remove ourselves from the list of modules, causing a crash later. Fix this by always adding ourself to the list of modules and always removing ourselves on destroy. See #565 --- src/pipewire/impl-module.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pipewire/impl-module.c b/src/pipewire/impl-module.c index 010991e42..7956bb520 100644 --- a/src/pipewire/impl-module.c +++ b/src/pipewire/impl-module.c @@ -239,6 +239,8 @@ pw_context_load_module(struct pw_context *context, filename = NULL; this->info.args = args ? strdup(args) : NULL; + spa_list_prepend(&context->module_list, &this->link); + this->global = pw_global_new(context, PW_TYPE_INTERFACE_Module, PW_VERSION_MODULE, @@ -249,8 +251,6 @@ pw_context_load_module(struct pw_context *context, if (this->global == NULL) goto error_no_global; - spa_list_prepend(&context->module_list, &this->link); - this->info.id = this->global->id; pw_properties_setf(this->properties, PW_KEY_OBJECT_ID, "%d", this->info.id); pw_properties_setf(this->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64, @@ -323,8 +323,9 @@ void pw_impl_module_destroy(struct pw_impl_module *module) pw_log_debug("%p: destroy", module); pw_impl_module_emit_destroy(module); + spa_list_remove(&module->link); + if (module->global) { - spa_list_remove(&module->link); spa_hook_remove(&module->global_listener); pw_global_destroy(module->global); }