c/swapchain: Close and remaining open FDs

This commit is contained in:
Jakob Bornecrantz 2020-05-30 16:58:34 +01:00
parent 753b910b5a
commit 09baeb91bc
2 changed files with 20 additions and 3 deletions

View file

@ -0,0 +1,2 @@
swapchain: Close any FDs that are still valid, for instance the ipc server
copies the FDs to the client.

View file

@ -7,13 +7,14 @@
* @ingroup comp_main
*/
#include <stdio.h>
#include <stdlib.h>
#include "util/u_misc.h"
#include "main/comp_compositor.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
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);
}