From 78c069ff874baa41f54801ad7fd727dc566bf3b6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 11 Aug 2022 12:06:28 +0200 Subject: [PATCH] potocol-native: improve error handling Init the compat types map a little earlier so that it is initialized when we try to clear it on error. Add the client listener earlier so that we can use the events to clean up the map, source and connection. --- src/modules/module-protocol-native.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 44a642534..980cccf7f 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -605,12 +605,15 @@ static struct client_data *client_new(struct server *s, int fd) if (client == NULL) goto exit; - this = pw_impl_client_get_user_data(client); spa_list_append(&s->this.client_list, &this->protocol_link); this->server = s; this->client = client; + pw_map_init(&this->compat_v2.types, 0, 32); + + pw_impl_client_add_listener(client, &this->client_listener, &client_events, this); + this->source = pw_loop_add_io(pw_context_get_main_loop(context), fd, SPA_IO_ERR | SPA_IO_HUP, true, connection_data, this); @@ -625,15 +628,11 @@ static struct client_data *client_new(struct server *s, int fd) goto cleanup_client; } - pw_map_init(&this->compat_v2.types, 0, 32); - pw_protocol_native_connection_add_listener(this->connection, &this->conn_listener, &server_conn_events, this); - pw_impl_client_add_listener(client, &this->client_listener, &client_events, this); - if ((res = pw_impl_client_register(client, NULL)) < 0) goto cleanup_client;