global: only unregister when it was registered

This commit is contained in:
Wim Taymans 2018-01-19 11:31:05 +01:00
parent c593d868fb
commit 04f77d2565

View file

@ -83,6 +83,7 @@ pw_global_new(struct pw_core *core,
this->bind = bind; this->bind = bind;
this->object = object; this->object = object;
this->properties = properties; this->properties = properties;
this->id = SPA_ID_INVALID;
pw_log_debug("global %p: new %s", this, pw_log_debug("global %p: new %s", this,
spa_type_map_get_type(core->type.map, this->type)); spa_type_map_get_type(core->type.map, this->type));
@ -236,17 +237,19 @@ void pw_global_destroy(struct pw_global *global)
pw_log_debug("global %p: destroy %u", global, global->id); pw_log_debug("global %p: destroy %u", global, global->id);
spa_list_for_each(registry, &core->registry_resource_list, link) { if (global->id != SPA_ID_INVALID) {
uint32_t permissions = pw_global_get_permissions(global, registry->client); spa_list_for_each(registry, &core->registry_resource_list, link) {
if (PW_PERM_IS_R(permissions)) uint32_t permissions = pw_global_get_permissions(global, registry->client);
pw_registry_resource_global_remove(registry, global->id); if (PW_PERM_IS_R(permissions))
pw_registry_resource_global_remove(registry, global->id);
}
pw_map_remove(&core->globals, global->id);
spa_list_remove(&global->link);
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_removed, global);
} }
pw_map_remove(&core->globals, global->id);
spa_list_remove(&global->link);
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_removed, global);
if (global->properties) if (global->properties)
pw_properties_free(global->properties); pw_properties_free(global->properties);