[PATCH wayland 5/9] connection: Close fds from half demarshalled closures

Derek Foreman derekf at osg.samsung.com
Fri Apr 7 20:27:51 UTC 2017


If we fail to demarshal a closure we need to close any fds we've
already removed from the buffer.  The rest will be cleaned up when
client_destroy results in a connection_flush.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
 src/connection.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 22bf836..934fddf 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -631,6 +631,8 @@ wl_connection_demarshal(struct wl_connection *connection,
 {
 	uint32_t *p, *next, *end, length, id;
 	int fd;
+	int fds[WL_CLOSURE_MAX_ARGS];
+	unsigned int fd_count = 0;
 	char *s;
 	unsigned int i, count, num_arrays;
 	const char *signature;
@@ -781,6 +783,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 			wl_buffer_copy(&connection->fds_in, &fd, sizeof fd);
 			connection->fds_in.tail += sizeof fd;
 			closure->args[i].h = fd;
+			fds[fd_count++] = fd;
 			break;
 		default:
 			wl_abort("unknown type\n");
@@ -796,6 +799,8 @@ wl_connection_demarshal(struct wl_connection *connection,
 	return closure;
 
  err:
+	for (i = 0; i < fd_count; i++)
+		close(fds[i]);
 	wl_closure_destroy(closure);
 	wl_connection_consume(connection, size);
 
-- 
2.11.0



More information about the wayland-devel mailing list