[Mesa-stable] [PATCH 3/5] st/xa: fd management cleanups

Emil Velikov emil.l.velikov at gmail.com
Mon Nov 23 12:26:57 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/state_trackers/xa/xa_tracker.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/xa/xa_tracker.c b/src/gallium/state_trackers/xa/xa_tracker.c
index faa630c..d57464b 100644
--- a/src/gallium/state_trackers/xa/xa_tracker.c
+++ b/src/gallium/state_trackers/xa/xa_tracker.c
@@ -152,11 +152,15 @@ xa_tracker_create(int drm_fd)
     struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker));
     enum xa_surface_type stype;
     unsigned int num_formats;
+    int fd = -1;
 
     if (!xa)
 	return NULL;
 
-    if (pipe_loader_drm_probe_fd(&xa->dev, dup(drm_fd)))
+    if (drm_fd < 0 || (fd = dup(drm_fd)) < 0)
+	goto out_no_fd;
+
+    if (pipe_loader_drm_probe_fd(&xa->dev, fd))
 	xa->screen = pipe_loader_create_screen(xa->dev);
 
     if (!xa->screen)
@@ -208,6 +212,9 @@ xa_tracker_create(int drm_fd)
  out_no_screen:
     if (xa->dev)
 	pipe_loader_release(&xa->dev, 1);
+    fd = -1;
+ out_no_fd:
+    close(fd);
     free(xa);
     return NULL;
 }
-- 
2.6.2



More information about the mesa-stable mailing list