egl/dri2: do not leak dri2_dpy->driver_name
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 2 Jun 2014 11:26:17 +0000 (12:26 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 9 Jun 2014 21:56:00 +0000 (22:56 +0100)
Originally all hardware drivers duplicate the driver_name string
from an external source, while for the software rasterizer we set
it to "swrast". Follow the example set by hw drivers this way
we can free the string at dri2_terminate().

v2: Use strdup over strndup. Suggested by Ilia Mirkin.
v3: Handle platform_drm in a similar manner. Cleanup swrast
driver_name in error path.

Cc: Chia-I Wu <olv@lunarg.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/platform_drm.c
src/egl/drivers/dri2/platform_x11.c

index c1497b802c9cd406d0edd74a3fd50435520afa3c..eb6abfd8c42d7912650087f11cd6afa078698561 100644 (file)
@@ -469,9 +469,7 @@ dri2_load_driver_swrast(_EGLDisplay *disp)
    struct dri2_egl_display *dri2_dpy = disp->DriverData;
    const __DRIextension **extensions;
 
-   dri2_dpy->driver_name = "swrast";
    extensions = dri2_open_driver(disp);
-
    if (!extensions)
       return EGL_FALSE;
 
@@ -673,6 +671,7 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
    if (dri2_dpy->driver)
       dlclose(dri2_dpy->driver);
    free(dri2_dpy->device_name);
+   free(dri2_dpy->driver_name);
 
    switch (disp->Platform) {
 #ifdef HAVE_X11_PLATFORM
index 52d8b49aa9e56f92cb220201b98b495c5815adcd..6227bc94cd5bcb05a7206046fb158af69c57c9c3 100644 (file)
@@ -526,7 +526,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
 
    dri2_dpy->fd = fd;
    dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd);
-   dri2_dpy->driver_name = dri2_dpy->gbm_dri->base.driver_name;
+   dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->base.driver_name);
 
    dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen;
    dri2_dpy->core = dri2_dpy->gbm_dri->core;
index 548334e3caadddf19bab495cdf6b7e0a7ad47af8..4ef1f3e4b440e0ff0ca8097f7c677b7473594825 100644 (file)
@@ -1076,6 +1076,11 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
       goto cleanup_dpy;
    }
 
+   /*
+    * 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->driver_name = strdup("swrast");
    if (!dri2_load_driver_swrast(disp))
       goto cleanup_conn;
 
@@ -1114,6 +1119,7 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
  cleanup_driver:
    dlclose(dri2_dpy->driver);
  cleanup_conn:
+   free(dri2_dpy->driver_name);
    if (disp->PlatformDisplay == NULL)
       xcb_disconnect(dri2_dpy->conn);
  cleanup_dpy: