egl/dri2: don't leak the fd on dri2_terminate
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 10 Sep 2015 13:41:38 +0000 (14:41 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Tue, 15 Sep 2015 11:39:02 +0000 (12:39 +0100)
Currently the check was incorrect as it did not consider the (unlikely)
case of fd == 0. In order to fix this we should first correctly
initialize it to -1, as the swrast implementations leave it set to zero
(props to calloc()).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Boyan Ding <boyan.j.ding@gmail.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/platform_wayland.c
src/egl/drivers/dri2/platform_x11.c

index eb56113a4ea7814f1bad687af6598d9c51be6a83..1740ee3dc4782f8dee6bcc4abb3d890b18afded0 100644 (file)
@@ -786,7 +786,7 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
 
    if (dri2_dpy->own_dri_screen)
       dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen);
-   if (dri2_dpy->fd)
+   if (dri2_dpy->fd >= 0)
       close(dri2_dpy->fd);
    if (dri2_dpy->driver)
       dlclose(dri2_dpy->driver);
index dbc64ba2d8a5db2b4387c42b9c136a618eedfdbc..6cf5461d52c9fc17498b0f9641ac4e655432353b 100644 (file)
@@ -1804,6 +1804,7 @@ dri2_initialize_wayland_swrast(_EGLDriver *drv, _EGLDisplay *disp)
    if (roundtrip(dri2_dpy) < 0 || dri2_dpy->formats == 0)
       goto cleanup_shm;
 
+   dri2_dpy->fd = -1;
    dri2_dpy->driver_name = strdup("swrast");
    if (!dri2_load_driver_swrast(disp))
       goto cleanup_shm;
index bf7d2bea4c1f9c8c196bb04b9a3b7bae8a24823c..7991fc2b67b4c9d66625caa654eeb70021ea9b1b 100644 (file)
@@ -1161,6 +1161,7 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
     * Every hardware driver_name is set using strdup. Doing the same in
     * here will allow is to simply free the memory at dri2_terminate().
     */
+   dri2_dpy->fd = -1;
    dri2_dpy->driver_name = strdup("swrast");
    if (!dri2_load_driver_swrast(disp))
       goto cleanup_conn;