proxy: improve cleanup

Remove the core_proxy from objects so that it doesn't try to use it
when it's being destroyed.
We need to recheck the core_proxy because it might have been removed
in the destroy signal.
This commit is contained in:
Wim Taymans 2019-12-06 17:11:03 +01:00
parent 7b0b5b77c3
commit 05565b21b1
2 changed files with 11 additions and 7 deletions

View file

@ -167,9 +167,14 @@ void *pw_core_proxy_get_user_data(struct pw_core_proxy *core_proxy)
static int destroy_proxy(void *object, void *data)
{
struct pw_core_proxy *core_proxy = data;
struct pw_proxy *p = object;
if (object && object != core_proxy)
pw_proxy_destroy(object);
if (object == NULL)
return 0;
p->core_proxy = NULL;
if (object != core_proxy)
pw_proxy_remove(p);
return 0;
}

View file

@ -200,8 +200,6 @@ void pw_proxy_add_object_listener(struct pw_proxy *proxy,
SPA_EXPORT
void pw_proxy_destroy(struct pw_proxy *proxy)
{
struct pw_core_proxy *core_proxy = proxy->core_proxy;
if (!proxy->zombie) {
pw_log_debug(NAME" %p: destroy %u", proxy, proxy->id);
pw_proxy_emit_destroy(proxy);
@ -209,15 +207,16 @@ void pw_proxy_destroy(struct pw_proxy *proxy)
if (!proxy->removed) {
/* if the server did not remove this proxy, remove ourselves
* from the proxy objects and schedule a destroy. */
if (core_proxy) {
if (proxy->core_proxy) {
proxy->zombie = true;
pw_core_proxy_destroy(core_proxy, proxy);
pw_core_proxy_destroy(proxy->core_proxy, proxy);
} else {
proxy->removed = true;
}
}
if (proxy->removed) {
pw_map_remove(&core_proxy->objects, proxy->id);
if (proxy->core_proxy)
pw_map_remove(&proxy->core_proxy->objects, proxy->id);
pw_proxy_unref(proxy);
}