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.

Signed-off-by: Derek Foreman <[email protected]>
---
 src/connection.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

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);
 }
-- 
2.15.0

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to