aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2015-11-23 20:26:56 +0000
committerEmil Velikov <[email protected]>2015-11-29 14:39:03 +0000
commitd90ba57c08dc51579c92224c7eedfc9f88f47853 (patch)
tree51b5a807334baf4b9aa6c7ad2d529671009a6480
parent5f92906b876d5463efba3ffb19c1de0dcb3c755f (diff)
st/dri: fd management cleanups
Add some checks if the original/dup'd fd is valid and ensure that we don't leak it on error. The former is implicitly handled within the pipe_loader, although let's make things explicit and check beforehand. Spotted by Coverity (CID 1339865) Cc: [email protected] Signed-off-by: Emil Velikov <[email protected]>
-rw-r--r--src/gallium/state_trackers/dri/dri2.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index beb0866c83f..a11a6cbbb0c 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1446,6 +1446,7 @@ dri2_init_screen(__DRIscreen * sPriv)
struct pipe_screen *pscreen = NULL;
const struct drm_conf_ret *throttle_ret;
const struct drm_conf_ret *dmabuf_ret;
+ int fd = -1;
screen = CALLOC_STRUCT(dri_screen);
if (!screen)
@@ -1457,7 +1458,10 @@ dri2_init_screen(__DRIscreen * sPriv)
sPriv->driverPrivate = (void *)screen;
- if (pipe_loader_drm_probe_fd(&screen->dev, dup(screen->fd)))
+ if (screen->fd < 0 || (fd = dup(screen->fd)) < 0)
+ goto fail;
+
+ if (pipe_loader_drm_probe_fd(&screen->dev, fd))
pscreen = pipe_loader_create_screen(screen->dev);
if (!pscreen)
@@ -1502,6 +1506,8 @@ fail:
dri_destroy_screen_helper(screen);
if (screen->dev)
pipe_loader_release(&screen->dev, 1);
+ else
+ close(fd);
FREE(screen);
return NULL;
}
@@ -1519,6 +1525,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
struct dri_screen *screen;
struct pipe_screen *pscreen = NULL;
uint64_t cap;
+ int fd = -1;
screen = CALLOC_STRUCT(dri_screen);
if (!screen)
@@ -1529,7 +1536,10 @@ dri_kms_init_screen(__DRIscreen * sPriv)
sPriv->driverPrivate = (void *)screen;
- if (pipe_loader_sw_probe_kms(&screen->dev, dup(screen->fd)))
+ if (screen->fd < 0 || (fd = dup(screen->fd)) < 0)
+ goto fail;
+
+ if (pipe_loader_sw_probe_kms(&screen->dev, fd))
pscreen = pipe_loader_create_screen(screen->dev);
if (!pscreen)
@@ -1557,6 +1567,8 @@ fail:
dri_destroy_screen_helper(screen);
if (screen->dev)
pipe_loader_release(&screen->dev, 1);
+ else
+ close(fd);
FREE(screen);
#endif // GALLIUM_SOFTPIPE
return NULL;