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@intel.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16333>
This commit is contained in:
Jason Ekstrand 2020-03-02 17:16:33 -06:00 committed by Marge Bot
parent ae6d32c938
commit c72ff19a9e
5 changed files with 10 additions and 9 deletions

View file

@ -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],

View file

@ -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);

View file

@ -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 {

View file

@ -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);

View file

@ -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 =