[Mesa-dev] [PATCH 5/5] freedreno: replace calls to dup(2) with fcntl(F_DUPFD_CLOEXEC)

Matt Whitlock freedesktop at mattwhitlock.name
Tue Mar 27 00:57:33 UTC 2018


Without this fix, duplicated file descriptors leak into child processes.
See commit aaac913e901229d11a1894f6aaf646de6b1a542c for one instance
where the same fix was employed.

Signed-off-by: Matt Whitlock <freedesktop at mattwhitlock.name>
---
 src/gallium/drivers/freedreno/freedreno_fence.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_fence.c b/src/gallium/drivers/freedreno/freedreno_fence.c
index 1925f726a2..e49c276f29 100644
--- a/src/gallium/drivers/freedreno/freedreno_fence.c
+++ b/src/gallium/drivers/freedreno/freedreno_fence.c
@@ -124,7 +124,7 @@ void fd_create_fence_fd(struct pipe_context *pctx,
 		enum pipe_fd_type type)
 {
 	assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
-	*pfence = fence_create(fd_context(pctx), NULL, 0, dup(fd));
+	*pfence = fence_create(fd_context(pctx), NULL, 0, fcntl(fd, F_DUPFD_CLOEXEC, 3));
 }
 
 void fd_fence_server_sync(struct pipe_context *pctx,
@@ -144,7 +144,7 @@ int fd_fence_get_fd(struct pipe_screen *pscreen,
 		struct pipe_fence_handle *fence)
 {
 	fence_flush(fence);
-	return dup(fence->fence_fd);
+	return fcntl(fence->fence_fd, F_DUPFD_CLOEXEC, 3);
 }
 
 struct pipe_fence_handle * fd_fence_create(struct fd_batch *batch)
-- 
2.16.3



More information about the mesa-dev mailing list