protocol-native: ref the client while emiting error

Increase the client refcount while we emit an error to make sure
it doesn't get destroyed in the callbacks.

See #340
This commit is contained in:
Wim Taymans 2020-10-21 13:19:49 +02:00
parent 48d1b8d57d
commit 64913f4c7c

View file

@ -727,11 +727,15 @@ on_remote_data(void *data, int fd, uint32_t mask)
{
struct client *impl = data;
struct pw_core *this = impl->this.core;
struct pw_proxy *core_proxy = (struct pw_proxy*)this;
struct pw_protocol_native_connection *conn = impl->connection;
struct pw_context *context = pw_core_get_context(this);
struct pw_loop *loop = pw_context_get_main_loop(context);
int res;
core_proxy->refcount++;
impl->ref++;
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
res = -EPIPE;
goto error;
@ -752,16 +756,20 @@ on_remote_data(void *data, int fd, uint32_t mask)
if ((res = process_remote(impl)) < 0)
goto error;
}
done:
client_unref(impl);
pw_proxy_unref(core_proxy);
return;
error:
pw_log_debug(NAME" %p: got connection error %d (%s)", impl, res, spa_strerror(res));
pw_proxy_notify((struct pw_proxy*)this,
struct pw_core_events, error, 0, 0,
this->recv_seq, res, "connection error");
if (impl->source) {
pw_loop_destroy_source(loop, impl->source);
impl->source = NULL;
}
pw_proxy_notify(core_proxy,
struct pw_core_events, error, 0, 0,
this->recv_seq, res, "connection error");
goto done;
}
static void on_need_flush(void *data)