[PATCHv2 12/13] xfree86: fix memory leaks in configLayout

Nicolas PENINGUY nico at lostgeeks.org
Mon Mar 28 17:01:28 PDT 2011


On Mon, 2011-03-28 at 16:14 +0300, Tiago Vignatti wrote:
>      count = 0;
>      while (idp) {
> -	if (!configDevice(&gdp[count], idp->inactive_device, FALSE)) {
> -	    free(gdp);
> -	    return FALSE;
> -	}
> +	if (!configDevice(&gdp[count], idp->inactive_device, FALSE))
> +	    goto bail;
>          count++;
>          idp = (XF86ConfInactivePtr)idp->list.next;
>      }

Since count is reset to 0 at the start of this loop, if configDevice()
fails at the first iteration for example, only slp[0].screen will be
freed in the "bail" part, while we might have allocated more than one
element in the allocation loop.

Moreover the count variable is first used in

	while (adjp) {

And then in

	while (idp) {

So it is counting different things I guess. The count of "adjp" needs to
be remembered I think, with special care for the 0 case:

	    if (!count)
	    {
	        slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));


Nicolas




More information about the xorg-devel mailing list