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.
This commit is contained in:
Wim Taymans 2022-08-11 12:06:28 +02:00
parent d7da581b9c
commit 78c069ff87

View file

@ -605,12 +605,15 @@ static struct client_data *client_new(struct server *s, int fd)
if (client == NULL) if (client == NULL)
goto exit; goto exit;
this = pw_impl_client_get_user_data(client); this = pw_impl_client_get_user_data(client);
spa_list_append(&s->this.client_list, &this->protocol_link); spa_list_append(&s->this.client_list, &this->protocol_link);
this->server = s; this->server = s;
this->client = client; 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), this->source = pw_loop_add_io(pw_context_get_main_loop(context),
fd, SPA_IO_ERR | SPA_IO_HUP, true, fd, SPA_IO_ERR | SPA_IO_HUP, true,
connection_data, this); connection_data, this);
@ -625,15 +628,11 @@ static struct client_data *client_new(struct server *s, int fd)
goto cleanup_client; goto cleanup_client;
} }
pw_map_init(&this->compat_v2.types, 0, 32);
pw_protocol_native_connection_add_listener(this->connection, pw_protocol_native_connection_add_listener(this->connection,
&this->conn_listener, &this->conn_listener,
&server_conn_events, &server_conn_events,
this); this);
pw_impl_client_add_listener(client, &this->client_listener, &client_events, this);
if ((res = pw_impl_client_register(client, NULL)) < 0) if ((res = pw_impl_client_register(client, NULL)) < 0)
goto cleanup_client; goto cleanup_client;