From b08da23715d62f7b8b048d15b256f2e559664cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Tue, 28 Dec 2021 19:21:01 +0100 Subject: [PATCH] pulse-server: module: do not schedule unloading multiple times While it is not a problem since `module_free()` calls `pw_work_queue_cancel()`, it is completely unnecessary to do it more than once. Introduce a new flag on the module which stores whether or not an unloading has been scheduled. --- src/modules/module-protocol-pulse/module.c | 7 +++++-- src/modules/module-protocol-pulse/module.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/module-protocol-pulse/module.c b/src/modules/module-protocol-pulse/module.c index f87889d5d..57790a6ae 100644 --- a/src/modules/module-protocol-pulse/module.c +++ b/src/modules/module-protocol-pulse/module.c @@ -50,8 +50,11 @@ static void on_module_unload(void *obj, void *data, int res, uint32_t id) void module_schedule_unload(struct module *module) { - struct impl *impl = module->impl; - pw_work_queue_add(impl->work_queue, module, 0, on_module_unload, impl); + if (module->unloading) + return; + + pw_work_queue_add(module->impl->work_queue, module, 0, on_module_unload, NULL); + module->unloading = true; } struct module *module_new(struct impl *impl, const struct module_methods *methods, size_t user_data) diff --git a/src/modules/module-protocol-pulse/module.h b/src/modules/module-protocol-pulse/module.h index b5ec49df4..f621edfa5 100644 --- a/src/modules/module-protocol-pulse/module.h +++ b/src/modules/module-protocol-pulse/module.h @@ -66,6 +66,7 @@ struct module { struct spa_hook_list listener_list; void *user_data; unsigned int loaded:1; + unsigned int unloading:1; }; #define module_emit_loaded(m,r) spa_hook_list_call(&m->listener_list, struct module_events, loaded, 0, r)