egl/drm: Duplicate fd with F_DUPFD_CLOEXEC to prevent leak
authorDerek Foreman <derekf@osg.samsung.com>
Wed, 17 Jun 2015 16:28:48 +0000 (11:28 -0500)
committerEmil Velikov <emil.l.velikov@gmail.com>
Tue, 23 Jun 2015 15:54:47 +0000 (16:54 +0100)
Replacing dup() with fcntl F_DUPFD_CLOEXEC creates the duplicate
file descriptor with CLOEXEC so it won't be leaked to child
processes if the process fork()s later.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
src/egl/drivers/dri2/platform_drm.c

index 3391afc635c438fbfe9bef5a0d983f723bc3d28e..c97c54fb58be5d3901222985710c6060e8ee25b4 100644 (file)
@@ -632,7 +632,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
    }
 
    if (fd < 0) {
-      fd = dup(gbm_device_get_fd(gbm));
+      fd = fcntl(gbm_device_get_fd(gbm), F_DUPFD_CLOEXEC, 3);
       if (fd < 0) {
          free(dri2_dpy);
          return EGL_FALSE;