[PATCH] Replace malloc with calloc to initialize the buffers[] as NULL in do_get_buffers function

Pauli Nieminen ext-pauli.nieminen at nokia.com
Fri Feb 11 02:05:58 PST 2011


On 10/02/11 20:19 -0500, ext Kristian Høgsberg wrote:
> From: Justin Dou <Justin.Dou at intel.com>
> 
> The calling for allocate_or_reuse_buffer may fail due to some reason, e.g. out of memory.
> If the buffers[] were not initialized to be NULL, the following err_out may try to access an illegal memory, which will cause X crash afterward.
> 
> Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>

This should be applied to 1.9 branch too.

Reviewed-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>

> Signed-off-by: Justin Dou <Justin.Dou at intel.com>
> ---
>  hw/xfree86/dri2/dri2.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
> index 34f735f..5d31e77 100644
> --- a/hw/xfree86/dri2/dri2.c
> +++ b/hw/xfree86/dri2/dri2.c
> @@ -403,7 +403,7 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
>  	&& (pDraw->height == pPriv->height)
>  	&& (pPriv->serialNumber == DRI2DrawableSerial(pDraw));
>  
> -    buffers = malloc((count + 1) * sizeof(buffers[0]));
> +    buffers = calloc((count + 1), sizeof(buffers[0]));
>  
>      for (i = 0; i < count; i++) {
>  	const unsigned attachment = *(attachments++);
> -- 
> 1.7.2.2
> 
> _______________________________________________
> 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


More information about the xorg-devel mailing list