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

Jeremy Huddleston jeremyhu at apple.com
Tue Oct 4 19:51:15 PDT 2011


reviewed and pulled into my tree for my next pull request.

On Sep 17, 2011, at 9:55 AM, 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;
>     }
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 

---
Jeremy Huddleston

Rebuild Sudan
 - Board of Directors
 - http://www.rebuildsudan.org

Berkeley Foundation for Opportunities in Information Technology
 - Advisory Board
 - http://www.bfoit.org



More information about the xorg-devel mailing list