aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2017-12-06 11:22:20 -0600
committerDaniel Stone <daniels@collabora.com>2017-12-27 14:14:31 +0000
commit46e4ea43a2ec546211f72be84b6a55188fb61626 (patch)
tree76804d7d81ef7389e3b7f300e9b8630a73534465 /src
parentconnection: Clear fds we shouldn't close to -1 (diff)
downloadwayland-46e4ea43a2ec546211f72be84b6a55188fb61626.tar
wayland-46e4ea43a2ec546211f72be84b6a55188fb61626.tar.gz
wayland-46e4ea43a2ec546211f72be84b6a55188fb61626.tar.bz2
wayland-46e4ea43a2ec546211f72be84b6a55188fb61626.tar.lz
wayland-46e4ea43a2ec546211f72be84b6a55188fb61626.tar.xz
wayland-46e4ea43a2ec546211f72be84b6a55188fb61626.tar.zst
wayland-46e4ea43a2ec546211f72be84b6a55188fb61626.zip
connection: Make wl_closure_destroy() close fds of undispatched closures
When we have a closure that can't be dispatched for some reason, and it contains file descriptors, we must close those descriptors to prevent leaking them. Previous commits ensure that only FDs belonging to this invocation of the closure, i.e. not FDs provided by the client for marshalling, nor FDs which have already been dispatched to either client or server, will be left in the closure by destroy time. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'src')
-rw-r--r--src/connection.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/connection.c b/src/connection.c
index 29f565b..e92de79 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1273,8 +1273,29 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
fprintf(stderr, ")\n");
}
+static int
+wl_closure_close_fds(struct wl_closure *closure)
+{
+ int i;
+ struct argument_details arg;
+ const char *signature = closure->message->signature;
+
+ for (i = 0; i < closure->count; i++) {
+ signature = get_next_argument(signature, &arg);
+ if (arg.type == 'h' && closure->args[i].h != -1)
+ close(closure->args[i].h);
+ }
+
+ return 0;
+}
+
void
wl_closure_destroy(struct wl_closure *closure)
{
+ /* wl_closure_destroy has free() semantics */
+ if (!closure)
+ return;
+
+ wl_closure_close_fds(closure);
free(closure);
}