st/xa: replace call to dup(2) with fcntl(F_DUPFD_CLOEXEC)
authorMatt Whitlock <freedesktop@mattwhitlock.name>
Sun, 2 Oct 2016 03:49:44 +0000 (23:49 -0400)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Tue, 4 Oct 2016 09:09:01 +0000 (11:09 +0200)
Without this fix, duplicated file descriptors leak into child processes.
See commit aaac913e901229d11a1894f6aaf646de6b1a542c for one instance
where the same fix was employed.

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Matt Whitlock <freedesktop@mattwhitlock.name>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/state_trackers/xa/xa_tracker.c

index d98bd2dc922e37fbff8930079779994f659da006..03a3abf6835ad193bac997e2b99f0f9e75824c27 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include <unistd.h>
+#include <fcntl.h>
 #include "xa_tracker.h"
 #include "xa_priv.h"
 #include "pipe/p_state.h"
@@ -157,7 +158,7 @@ xa_tracker_create(int drm_fd)
     if (!xa)
        return NULL;
 
-    if (drm_fd < 0 || (fd = dup(drm_fd)) < 0)
+    if (drm_fd < 0 || (fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 3)) < 0)
        goto out_no_fd;
 
     if (pipe_loader_drm_probe_fd(&xa->dev, fd))