mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
fix a socket leak
Let the loop source free the sockets. Free the write fd in the stream.
This commit is contained in:
parent
577f86be0d
commit
174d34ada6
3 changed files with 31 additions and 39 deletions
|
|
@ -65,8 +65,6 @@ struct protocol_data {
|
|||
struct client {
|
||||
struct pw_protocol_client this;
|
||||
|
||||
int fd;
|
||||
|
||||
struct spa_source *source;
|
||||
|
||||
struct pw_protocol_native_connection *connection;
|
||||
|
|
@ -80,7 +78,6 @@ struct client {
|
|||
struct server {
|
||||
struct pw_protocol_server this;
|
||||
|
||||
int fd;
|
||||
int fd_lock;
|
||||
struct sockaddr_un addr;
|
||||
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
||||
|
|
@ -93,7 +90,6 @@ struct server {
|
|||
struct client_data {
|
||||
struct pw_client *client;
|
||||
struct spa_hook client_listener;
|
||||
int fd;
|
||||
struct spa_source *source;
|
||||
struct pw_protocol_native_connection *connection;
|
||||
bool busy;
|
||||
|
|
@ -217,7 +213,6 @@ static void client_free(void *data)
|
|||
spa_list_remove(&client->protocol_link);
|
||||
|
||||
pw_protocol_native_connection_destroy(this->connection);
|
||||
close(this->fd);
|
||||
}
|
||||
|
||||
static const struct pw_client_events client_events = {
|
||||
|
|
@ -254,10 +249,8 @@ static struct pw_client *client_new(struct server *s, int fd)
|
|||
|
||||
this = pw_client_get_user_data(client);
|
||||
this->client = client;
|
||||
this->fd = fd;
|
||||
this->source = pw_loop_add_io(pw_core_get_main_loop(core),
|
||||
this->fd,
|
||||
SPA_IO_ERR | SPA_IO_HUP, false, connection_data, this);
|
||||
fd, SPA_IO_ERR | SPA_IO_HUP, true, connection_data, this);
|
||||
if (this->source == NULL)
|
||||
goto no_source;
|
||||
|
||||
|
|
@ -376,27 +369,34 @@ socket_data(void *data, int fd, enum spa_io mask)
|
|||
static bool add_socket(struct pw_protocol *protocol, struct server *s)
|
||||
{
|
||||
socklen_t size;
|
||||
int fd;
|
||||
|
||||
if ((s->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0)
|
||||
return false;
|
||||
if ((fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0)
|
||||
goto error;
|
||||
|
||||
size = offsetof(struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
|
||||
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
|
||||
if (bind(fd, (struct sockaddr *) &s->addr, size) < 0) {
|
||||
pw_log_error("bind() failed with error: %m");
|
||||
return false;
|
||||
goto error_close;
|
||||
}
|
||||
|
||||
if (listen(s->fd, 128) < 0) {
|
||||
if (listen(fd, 128) < 0) {
|
||||
pw_log_error("listen() failed with error: %m");
|
||||
return false;
|
||||
goto error_close;
|
||||
}
|
||||
|
||||
s->loop = pw_core_get_main_loop(protocol->core);
|
||||
s->source = pw_loop_add_io(s->loop, s->fd, SPA_IO_IN, false, socket_data, s);
|
||||
s->source = pw_loop_add_io(s->loop, fd, SPA_IO_IN, true, socket_data, s);
|
||||
if (s->source == NULL)
|
||||
return false;
|
||||
goto error_close;
|
||||
|
||||
return true;
|
||||
|
||||
error_close:
|
||||
close(fd);
|
||||
error:
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
@ -561,11 +561,10 @@ static int impl_connect_fd(struct pw_protocol_client *client, int fd)
|
|||
&conn_events,
|
||||
impl);
|
||||
|
||||
impl->fd = fd;
|
||||
impl->source = pw_loop_add_io(remote->core->main_loop,
|
||||
fd,
|
||||
SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR,
|
||||
false, on_remote_data, impl);
|
||||
true, on_remote_data, impl);
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
@ -588,10 +587,6 @@ static void impl_disconnect(struct pw_protocol_client *client)
|
|||
if (impl->connection)
|
||||
pw_protocol_native_connection_destroy(impl->connection);
|
||||
impl->connection = NULL;
|
||||
|
||||
if (impl->fd != -1)
|
||||
close(impl->fd);
|
||||
impl->fd = -1;
|
||||
}
|
||||
|
||||
static void impl_destroy(struct pw_protocol_client *client)
|
||||
|
|
@ -599,6 +594,8 @@ static void impl_destroy(struct pw_protocol_client *client)
|
|||
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
|
||||
struct pw_remote *remote = client->remote;
|
||||
|
||||
impl_disconnect(client);
|
||||
|
||||
pw_loop_destroy_source(remote->core->main_loop, impl->flush_event);
|
||||
|
||||
spa_list_remove(&client->link);
|
||||
|
|
@ -625,7 +622,6 @@ impl_new_client(struct pw_protocol *protocol,
|
|||
this->disconnect = impl_disconnect;
|
||||
this->destroy = impl_destroy;
|
||||
|
||||
impl->fd = -1;
|
||||
impl->flush_event = pw_loop_add_event(remote->core->main_loop, do_flush_event, impl);
|
||||
|
||||
spa_list_append(&protocol->client_list, &this->link);
|
||||
|
|
@ -647,11 +643,9 @@ static void destroy_server(struct pw_protocol_server *server)
|
|||
pw_loop_destroy_source(s->loop, s->source);
|
||||
if (s->addr.sun_path[0])
|
||||
unlink(s->addr.sun_path);
|
||||
if (s->fd >= 0)
|
||||
close(s->fd);
|
||||
if (s->lock_addr[0])
|
||||
unlink(s->lock_addr);
|
||||
if (s->fd_lock >= 0)
|
||||
if (s->fd_lock != 1)
|
||||
close(s->fd_lock);
|
||||
free(s);
|
||||
}
|
||||
|
|
@ -686,7 +680,6 @@ impl_add_server(struct pw_protocol *protocol,
|
|||
if ((s = calloc(1, sizeof(struct server))) == NULL)
|
||||
return NULL;
|
||||
|
||||
s->fd = -1;
|
||||
s->fd_lock = -1;
|
||||
|
||||
this = &s->this;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue