From 09baeb91bc1a2b9cf6b045b221e0f5c90fd5528c Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 30 May 2020 16:58:34 +0100 Subject: [PATCH] c/swapchain: Close and remaining open FDs --- doc/changes/compositor/mr.359.2.md | 2 ++ src/xrt/compositor/main/comp_swapchain.c | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 doc/changes/compositor/mr.359.2.md diff --git a/doc/changes/compositor/mr.359.2.md b/doc/changes/compositor/mr.359.2.md new file mode 100644 index 000000000..b20e94999 --- /dev/null +++ b/doc/changes/compositor/mr.359.2.md @@ -0,0 +1,2 @@ +swapchain: Close any FDs that are still valid, for instance the ipc server +copies the FDs to the client. diff --git a/src/xrt/compositor/main/comp_swapchain.c b/src/xrt/compositor/main/comp_swapchain.c index a19333fc6..df885a043 100644 --- a/src/xrt/compositor/main/comp_swapchain.c +++ b/src/xrt/compositor/main/comp_swapchain.c @@ -7,13 +7,14 @@ * @ingroup comp_main */ -#include -#include - #include "util/u_misc.h" #include "main/comp_compositor.h" +#include +#include +#include + static void swapchain_destroy(struct xrt_swapchain *xsc) @@ -243,6 +244,11 @@ comp_swapchain_create(struct xrt_compositor *xc, COMP_DEBUG(c, "CREATE %p %dx%d", (void *)sc, width, height); + // Make sure the fds are invalid. + for (uint32_t i = 0; i < ARRAY_SIZE(sc->base.images); i++) { + sc->base.images[i].fd = -1; + } + for (uint32_t i = 0; i < num_images; i++) { ret = create_image_fd(c, bits, format, width, height, array_size, @@ -361,5 +367,14 @@ comp_swapchain_really_destroy(struct comp_swapchain *sc) &sc->images[i]); } + for (uint32_t i = 0; i < sc->base.base.num_images; i++) { + if (sc->base.images[i].fd < 0) { + continue; + } + + close(sc->base.images[i].fd); + sc->base.images[i].fd = -1; + } + free(sc); }