[Mesa-stable] [PATCH 4/5] auxiliary/vl/drm: fd management cleanups

Emil Velikov emil.l.velikov at gmail.com
Mon Nov 23 12:26:58 PST 2015


Analogous to previous commit.

Spotted by Coverity.

Cc: mesa-stable at lists.freedesktop.org
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/gallium/auxiliary/vl/vl_winsys_drm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/vl/vl_winsys_drm.c b/src/gallium/auxiliary/vl/vl_winsys_drm.c
index f993e2c..6d9d947 100644
--- a/src/gallium/auxiliary/vl/vl_winsys_drm.c
+++ b/src/gallium/auxiliary/vl/vl_winsys_drm.c
@@ -41,12 +41,16 @@ struct vl_screen *
 vl_drm_screen_create(int fd)
 {
    struct vl_screen *vscreen;
+   int new_fd = -1;
 
    vscreen = CALLOC_STRUCT(vl_screen);
    if (!vscreen)
       return NULL;
 
-   if (pipe_loader_drm_probe_fd(&vscreen->dev, dup(fd)))
+   if (fd < 0 || (new_fd = dup(fd)) < 0)
+      goto error;
+
+   if (pipe_loader_drm_probe_fd(&vscreen->dev, new_fd))
       vscreen->pscreen = pipe_loader_create_screen(vscreen->dev);
 
    if (!vscreen->pscreen)
@@ -63,6 +67,8 @@ vl_drm_screen_create(int fd)
 error:
    if (vscreen->dev)
       pipe_loader_release(&vscreen->dev, 1);
+   else
+      close(new_fd);
 
    FREE(vscreen);
    return NULL;
-- 
2.6.2



More information about the mesa-stable mailing list