From 94f2d53586ba9d8994c66307e983b1513bee6cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Tue, 20 May 2025 17:11:35 +0200 Subject: [PATCH] llvmpipe: Close mem_fd or dmabuf_fd on error The variable shadowing made the error path to leak these file descriptors. CID: 1596485, 1596493 Logically dead code Part-of: --- src/gallium/drivers/llvmpipe/lp_texture.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index f26b4c07015..9f99e61a69e 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -1388,7 +1388,7 @@ llvmpipe_resource_alloc_udmabuf(struct llvmpipe_screen *screen, size = align(size, alignment); - int mem_fd = memfd_create("lp_dma_buf", MFD_ALLOW_SEALING); + mem_fd = memfd_create("lp_dma_buf", MFD_ALLOW_SEALING); if (mem_fd == -1) goto fail; @@ -1409,7 +1409,7 @@ llvmpipe_resource_alloc_udmabuf(struct llvmpipe_screen *screen, .size = size }; - int dmabuf_fd = ioctl(screen->udmabuf_fd, UDMABUF_CREATE, &create); + dmabuf_fd = ioctl(screen->udmabuf_fd, UDMABUF_CREATE, &create); if (dmabuf_fd < 0) goto fail; @@ -1426,10 +1426,10 @@ llvmpipe_resource_alloc_udmabuf(struct llvmpipe_screen *screen, } fail: + if (dmabuf_fd >= 0) + close(dmabuf_fd); if (mem_fd != -1) close(mem_fd); - if (dmabuf_fd != -1) - close(dmabuf_fd); /* If we don't have access to the udmabuf device * or something else fails we return NULL */ return NULL;