diff options
| author | David Herrmann <dh.herrmann@googlemail.com> | 2012-10-11 23:37:45 +0200 |
|---|---|---|
| committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-10-15 16:12:46 -0400 |
| commit | cda89f3a42789771907a9d6a3159f7c22c99985e (patch) | |
| tree | 4325d9e501bbf89522802b30c698653744eb8ee3 /src/connection.c | |
| parent | wayland-util: return 0 on OOM in wl_map_insert_new() (diff) | |
| download | wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.tar wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.tar.gz wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.tar.bz2 wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.tar.lz wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.tar.xz wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.tar.zst wayland-cda89f3a42789771907a9d6a3159f7c22c99985e.zip | |
connection: close pending outgoing fds on shutdown
When destroying a wl_connection object, there might still be data in the
queue. We would leak open file-descriptors so we must close them.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'src/connection.c')
| -rw-r--r-- | src/connection.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/connection.c b/src/connection.c index 8497670..0df416a 100644 --- a/src/connection.c +++ b/src/connection.c @@ -167,9 +167,27 @@ wl_connection_create(int fd) return connection; } +static void +close_fds(struct wl_buffer *buffer) +{ + int fds[MAX_FDS_OUT], i, count; + size_t size; + + size = buffer->head - buffer->tail; + if (size == 0) + return; + + wl_buffer_copy(buffer, fds, size); + count = size / sizeof fds[0]; + for (i = 0; i < count; i++) + close(fds[i]); + buffer->tail += size; +} + void wl_connection_destroy(struct wl_connection *connection) { + close_fds(&connection->fds_out); close(connection->fd); free(connection); } @@ -206,23 +224,6 @@ build_cmsg(struct wl_buffer *buffer, char *data, int *clen) } static void -close_fds(struct wl_buffer *buffer) -{ - int fds[MAX_FDS_OUT], i, count; - size_t size; - - size = buffer->head - buffer->tail; - if (size == 0) - return; - - wl_buffer_copy(buffer, fds, size); - count = size / sizeof fds[0]; - for (i = 0; i < count; i++) - close(fds[i]); - buffer->tail += size; -} - -static void decode_cmsg(struct wl_buffer *buffer, struct msghdr *msg) { struct cmsghdr *cmsg; |
