aboutsummaryrefslogtreecommitdiffstats
path: root/src/egl/drivers/dri2
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2014-06-02 12:26:17 +0100
committerEmil Velikov <[email protected]>2014-06-09 22:56:00 +0100
commit5cb1cad0aef8d1c426207c955996278290e19e60 (patch)
tree9d977e87d776e61fa8ef84aa880c1db5b5536d90 /src/egl/drivers/dri2
parentc153b1f39b60f7a2ba59262b12b4597cbfbf36ca (diff)
egl/dri2: do not leak dri2_dpy->driver_name
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 <[email protected]> Signed-off-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/egl/drivers/dri2')
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c3
-rw-r--r--src/egl/drivers/dri2/platform_drm.c2
-rw-r--r--src/egl/drivers/dri2/platform_x11.c6
3 files changed, 8 insertions, 3 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index c1497b802c9..eb6abfd8c42 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -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
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 52d8b49aa9e..6227bc94cd5 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -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;
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index 548334e3caa..4ef1f3e4b44 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -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: