[PATCH xserver/hw/xfree86/modes/xf86Crtc.c] trivial memory leak

Matt Turner mattst88 at gmail.com
Sat Sep 17 10:04:02 PDT 2011


On Sat, Sep 17, 2011 at 12:55 PM,  <vdb at picaros.org> wrote:
> Anyone willing to review this triviality ? The code is included below.
>
> This patch fixes a memory leak in xf86CrtcCreate().  It frees the
> crtc->gamma_red buffer when a quit on error occurs.
>
> xf86CrtcPtr
> xf86CrtcCreate (ScrnInfoPtr             scrn,
>                const xf86CrtcFuncsRec  *funcs)
> <...>
>
>    crtc->gamma_size = 256;
> ->  crtc->gamma_red = malloc(3 * crtc->gamma_size * sizeof (CARD16));
>    if (!crtc->gamma_red) {
>        free(crtc);
>        return NULL;
>    }
>    crtc->gamma_green = crtc->gamma_red + crtc->gamma_size;
>    crtc->gamma_blue = crtc->gamma_green + crtc->gamma_size;
>
>    if (xf86_config->crtc)
>        crtcs = realloc(xf86_config->crtc,
>                          (xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
>    else
>        crtcs = malloc((xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
>    if (!crtcs)
>    {
> ->      free(crtc);
> ->      return NULL;
>    }
>
> Signed-off-by: Servaas Vandenberghe <vdb at picaros.org>
> diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
> index c2814d4..74c8d66 100644
> --- a/hw/xfree86/modes/xf86Crtc.c
> +++ b/hw/xfree86/modes/xf86Crtc.c
> @@ -133,6 +133,7 @@ xf86CrtcCreate (ScrnInfoPtr         scrn,
>        crtcs = malloc((xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
>     if (!crtcs)
>     {
> +       free(crtc->gamma_red);
>        free(crtc);
>        return NULL;
>     }

Good catch.

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the xorg-devel mailing list