From 49b0a8921cdbb846039847864860884f9fb9ebe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 25 Jan 2023 21:33:18 +0100 Subject: [PATCH] Use g_clear_fd() instead of open coding the same behavior Part-of: --- cogl/cogl/cogl-dma-buf-handle.c | 4 ++-- src/backends/native/meta-drm-buffer-dumb.c | 4 ++-- src/wayland/meta-wayland-dma-buf.c | 6 ++---- src/wayland/meta-xwayland.c | 7 ++----- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cogl/cogl/cogl-dma-buf-handle.c b/cogl/cogl/cogl-dma-buf-handle.c index 5b18f1030..b8d0929d2 100644 --- a/cogl/cogl/cogl-dma-buf-handle.c +++ b/cogl/cogl/cogl-dma-buf-handle.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -95,8 +96,7 @@ cogl_dma_buf_handle_free (CoglDmaBufHandle *dmabuf_handle) if (dmabuf_handle->destroy_func) g_clear_pointer (&dmabuf_handle->user_data, dmabuf_handle->destroy_func); - if (dmabuf_handle->dmabuf_fd != -1) - close (dmabuf_handle->dmabuf_fd); + g_clear_fd (&dmabuf_handle->dmabuf_fd, NULL); g_free (dmabuf_handle); } diff --git a/src/backends/native/meta-drm-buffer-dumb.c b/src/backends/native/meta-drm-buffer-dumb.c index 25d0ed328..29fb8f15d 100644 --- a/src/backends/native/meta-drm-buffer-dumb.c +++ b/src/backends/native/meta-drm-buffer-dumb.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -343,8 +344,7 @@ destroy_dumb_buffer (MetaDrmBufferDumb *buffer_dumb) }; drmIoctl (fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg); - if (buffer_dumb->dmabuf_fd != -1) - close (buffer_dumb->dmabuf_fd); + g_clear_fd (&buffer_dumb->dmabuf_fd, NULL); } static void diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c index 7f2348d77..6f265a83e 100644 --- a/src/wayland/meta-wayland-dma-buf.c +++ b/src/wayland/meta-wayland-dma-buf.c @@ -40,6 +40,7 @@ #include "wayland/meta-wayland-dma-buf.h" #include +#include #include #include #include @@ -1785,10 +1786,7 @@ meta_wayland_dma_buf_buffer_finalize (GObject *object) int i; for (i = 0; i < META_WAYLAND_DMA_BUF_MAX_FDS; i++) - { - if (dma_buf->fds[i] != -1) - close (dma_buf->fds[i]); - } + g_clear_fd (&dma_buf->fds[i], NULL); G_OBJECT_CLASS (meta_wayland_dma_buf_buffer_parent_class)->finalize (object); } diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c index c3657cbd3..b8c858483 100644 --- a/src/wayland/meta-xwayland.c +++ b/src/wayland/meta-xwayland.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -254,11 +255,7 @@ try_display (int display, g_free (filename); filename = NULL; - if (fd >= 0) - { - close (fd); - fd = -1; - } + g_clear_fd (&fd, NULL); } *filename_out = filename;