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
This commit is contained in:
Wim Taymans 2021-03-26 20:49:57 +01:00
parent 511cb28e17
commit ea5a830c8a
2 changed files with 3 additions and 2 deletions

View file

@ -540,7 +540,7 @@ struct pw_global *pw_context_find_global(struct pw_context *context, uint32_t id
struct pw_global *global; struct pw_global *global;
global = pw_map_lookup(&context->globals, id); global = pw_map_lookup(&context->globals, id);
if (global == NULL || global->destroyed) { if (global == NULL || !global->registered) {
errno = ENOENT; errno = ENOENT;
return NULL; return NULL;
} }

View file

@ -169,7 +169,6 @@ static int global_unregister(struct pw_global *global)
} }
spa_list_remove(&global->link); spa_list_remove(&global->link);
pw_map_remove(&context->globals, global->id);
global->registered = false; global->registered = false;
pw_log_debug(NAME" %p: unregistered %u", global, global->id); pw_log_debug(NAME" %p: unregistered %u", global, global->id);
@ -373,6 +372,7 @@ SPA_EXPORT
void pw_global_destroy(struct pw_global *global) void pw_global_destroy(struct pw_global *global)
{ {
struct pw_resource *resource; struct pw_resource *resource;
struct pw_context *context = global->context;
global->destroyed = true; global->destroyed = true;
@ -387,6 +387,7 @@ void pw_global_destroy(struct pw_global *global)
pw_log_debug(NAME" %p: free", global); pw_log_debug(NAME" %p: free", global);
pw_global_emit_free(global); pw_global_emit_free(global);
pw_map_remove(&context->globals, global->id);
spa_hook_list_clean(&global->listener_list); spa_hook_list_clean(&global->listener_list);
pw_properties_free(global->properties); pw_properties_free(global->properties);