Mesa (main): vulkan/wsi: Close file descriptors in wsi_destroy_image
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed May 4 22:40:53 UTC 2022
Module: Mesa
Branch: main
Commit: c72ff19a9ef7ef0fbb5b9b7ae8c7224523297a62
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c72ff19a9ef7ef0fbb5b9b7ae8c7224523297a62
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Mon Mar 2 17:16:33 2020 -0600
vulkan/wsi: Close file descriptors in wsi_destroy_image
Most of the time, this is a non-issue because the WSI back-end closes
them as part of handing them to the window-system and sets fds[*] to -1.
The one exception here was Wayland which was closing them but leaving
fds[*] pointing to bogus file descriptors. Having wsi_destroy_image
close them makes clean-up easier and more reliable.
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Simon Ser <contact at emersion.fr>
Reviewed-by: Adam Jackson <ajax at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16333>
---
src/vulkan/wsi/wsi_common.c | 5 +++++
src/vulkan/wsi/wsi_common_display.c | 4 ----
src/vulkan/wsi/wsi_common_drm.c | 6 +-----
src/vulkan/wsi/wsi_common_private.h | 3 +++
src/vulkan/wsi/wsi_common_wayland.c | 1 +
5 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index 10f98844098..a2ba2021fb9 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -512,6 +512,11 @@ wsi_destroy_image(const struct wsi_swapchain *chain,
{
const struct wsi_device *wsi = chain->wsi;
+ for (int p = 0; p < image->num_planes; p++) {
+ if (image->fds[p] >= 0)
+ close(image->fds[p]);
+ }
+
if (image->buffer.blit_cmd_buffers) {
for (uint32_t i = 0; i < wsi->queue_family_count; i++) {
wsi->FreeCommandBuffers(chain->device, chain->cmd_pools[i],
diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
index 3c9f3b1c32b..410dc4220c2 100644
--- a/src/vulkan/wsi/wsi_common_display.c
+++ b/src/vulkan/wsi/wsi_common_display.c
@@ -1136,10 +1136,6 @@ fail_handle:
for (unsigned int i = 0; i < image->base.num_planes; i++) {
if (image->buffer[i])
wsi_display_destroy_buffer(wsi, image->buffer[i]);
- if (image->base.fds[i] != -1) {
- close(image->base.fds[i]);
- image->base.fds[i] = -1;
- }
}
wsi_destroy_image(&chain->base, &image->base);
diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c
index 72af5b2c820..9b00ed2218a 100644
--- a/src/vulkan/wsi/wsi_common_drm.c
+++ b/src/vulkan/wsi/wsi_common_drm.c
@@ -393,12 +393,8 @@ wsi_create_native_image_mem(const struct wsi_swapchain *chain,
image->fds[p] = fd;
} else {
image->fds[p] = os_dupfd_cloexec(fd);
- if (image->fds[p] == -1) {
- for (uint32_t i = 0; i < p; i++)
- close(image->fds[i]);
-
+ if (image->fds[p] == -1)
return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
}
}
} else {
diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h
index af190ce501b..c6e575cd518 100644
--- a/src/vulkan/wsi/wsi_common_private.h
+++ b/src/vulkan/wsi/wsi_common_private.h
@@ -182,6 +182,9 @@ VkResult
wsi_create_image(const struct wsi_swapchain *chain,
const struct wsi_image_info *info,
struct wsi_image *image);
+void
+wsi_image_init(struct wsi_image *image);
+
void
wsi_destroy_image(const struct wsi_swapchain *chain,
struct wsi_image *image);
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index 0678556105e..ac2d918d127 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -1167,6 +1167,7 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain,
image->base.drm_modifier >> 32,
image->base.drm_modifier & 0xffffffff);
close(image->base.fds[i]);
+ image->base.fds[i] = -1;
}
image->buffer =
More information about the mesa-commit
mailing list