[PATCH:libX11 09/12] Region.c: ensure region size is updated correctly if realloc fails

Matthieu Herrb matthieu.herrb at laas.fr
Sun Aug 11 05:21:15 PDT 2013


On Sat, Aug 10, 2013 at 01:55:06PM -0700, Alan Coopersmith wrote:
> Don't want later users of the function to think there's more or less
> memory allocated than there really is.
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

For this one and the next one, I also wonder what happens in practice
if realloc fails. Can the application really continue with the smaller
than needed buffer ? 

> ---
>  src/Region.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/Region.c b/src/Region.c
> index d3d431a..ece9695 100644
> --- a/src/Region.c
> +++ b/src/Region.c
> @@ -525,6 +525,7 @@ miRegionCopy(
>  					 rgn->numRects * (sizeof(BOX)));
>  		if (! dstrgn->rects) {
>  		    Xfree(prevRects);
> +		    dstrgn->size = 0;
>  		    return;
>  		}
>              }
> @@ -978,11 +979,12 @@ miRegionOp(
>  	if (REGION_NOT_EMPTY(newReg))
>  	{
>  	    BoxPtr prev_rects = newReg->rects;
> -	    newReg->size = newReg->numRects;
>  	    newReg->rects = Xrealloc (newReg->rects,
> -				      sizeof(BoxRec) * newReg->size);
> +				      sizeof(BoxRec) * newReg->numRects);
>  	    if (! newReg->rects)
>  		newReg->rects = prev_rects;
> +	    else
> +		newReg->size = newReg->numRects;
>  	}
>  	else
>  	{
> -- 
> 1.7.9.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

-- 
Matthieu Herrb


More information about the xorg-devel mailing list