[PATCH v2 wayland 02/11] connection: Close fds from half marshalled closures

Derek Foreman derekf at osg.samsung.com
Thu Apr 13 16:51:44 UTC 2017


If we fail to completely marshal a closure then we need to close the fds
we created with dupfd.

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

diff --git a/src/connection.c b/src/connection.c
index 7fe35b5..22bf836 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -532,6 +532,7 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,
 	struct wl_closure *closure;
 	struct wl_object *object;
 	int i, count, fd, dup_fd;
+	int fds[WL_CLOSURE_MAX_ARGS], fd_count = 0;
 	const char *signature;
 	struct argument_details arg;
 
@@ -584,6 +585,7 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,
 			if (dup_fd < 0)
 				wl_abort("dup failed: %s\n", strerror(errno));
 			closure->args[i].h = dup_fd;
+			fds[fd_count++] = dup_fd;
 			break;
 		default:
 			wl_abort("unhandled format code: '%c'\n", arg.type);
@@ -599,6 +601,8 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,
 	return closure;
 
 err_null:
+	for (i = 0; i < fd_count; i++)
+		close(fds[i]);
 	wl_closure_destroy(closure);
 	wl_log("error marshalling arguments for %s (signature %s): "
 	       "null value passed for arg %i\n", message->name,
-- 
2.11.0



More information about the wayland-devel mailing list