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

Ilia Mirkin imirkin at alum.mit.edu
Sun Jun 1 07:36:01 PDT 2014


On Sun, Jun 1, 2014 at 10:19 AM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> Originally all hardware drivers duplicate the driver_name string
> from an external source, while for the software rasterizer we've
> set it to a literal. Follow the example set by hw drivers this way
> we can free the string at dri2_terminate().
>
> Cc: Chia-I Wu <olv at lunarg.com>
> Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
> ---
>  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..a2dc7ff 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 = strndup("swrast", sizeof("swrast"));

strdup("swrast") avoids the sizeof thing.

  -ilia


More information about the mesa-dev mailing list