From ea5a830c8a1c4b871e554c0f77fbea6599bc1506 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 26 Mar 2021 20:49:57 +0100 Subject: [PATCH] global: always remove from the global map We add the global to the global map to allocate an id. Remove the global from the map in _destroy() instead of _unregister() to make sure we always remove the global from the map, even if the global was not registered. See #973 --- src/pipewire/context.c | 2 +- src/pipewire/global.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index b23e0f9b5..396ba2f79 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -540,7 +540,7 @@ struct pw_global *pw_context_find_global(struct pw_context *context, uint32_t id struct pw_global *global; global = pw_map_lookup(&context->globals, id); - if (global == NULL || global->destroyed) { + if (global == NULL || !global->registered) { errno = ENOENT; return NULL; } diff --git a/src/pipewire/global.c b/src/pipewire/global.c index 0f9218e6e..ce29ed4fb 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -169,7 +169,6 @@ static int global_unregister(struct pw_global *global) } spa_list_remove(&global->link); - pw_map_remove(&context->globals, global->id); global->registered = false; pw_log_debug(NAME" %p: unregistered %u", global, global->id); @@ -373,6 +372,7 @@ SPA_EXPORT void pw_global_destroy(struct pw_global *global) { struct pw_resource *resource; + struct pw_context *context = global->context; global->destroyed = true; @@ -387,6 +387,7 @@ void pw_global_destroy(struct pw_global *global) pw_log_debug(NAME" %p: free", global); pw_global_emit_free(global); + pw_map_remove(&context->globals, global->id); spa_hook_list_clean(&global->listener_list); pw_properties_free(global->properties);