[Mesa-dev] [PATCH] egl/dri2: do not leak dri2_dpy->driver_name

Emil Velikov emil.l.velikov at gmail.com
Sun Jun 1 08:53:10 PDT 2014

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.

Cc: Chia-I Wu <olv at lunarg.com>
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>

Normally I prefer strn* functions, although in this case looks ugly.

Thanks for the suggestion Ilia.

 src/egl/drivers/dri2/egl_dri2.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index c1497b8..f10afed 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -469,7 +469,11 @@ dri2_load_driver_swrast(_EGLDisplay *disp)
    struct dri2_egl_display *dri2_dpy = disp->DriverData;
    const __DRIextension **extensions;
-   dri2_dpy->driver_name = "swrast";
+   /*
+    * Every hardware driver_name is set using strndup. Doing the same in
+    * here will allow is to simply free the memory at dri2_terminate().
+    */
+   dri2_dpy->driver_name = strdup("swrast");
    extensions = dri2_open_driver(disp);
    if (!extensions)
@@ -673,6 +677,7 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
    if (dri2_dpy->driver)
+   free(dri2_dpy->driver_name);
    switch (disp->Platform) {

More information about the mesa-dev mailing list