[PATCH xserver 2/4] dri2: Split resource tracking for DRI2Drawable and references to them

Adam Jackson ajax at nwnk.net
Mon Feb 8 21:59:29 UTC 2016


On Wed, 2016-02-03 at 09:54 +0000, Chris Wilson wrote:

> @@ -203,6 +203,11 @@ DRI2AllocateDrawable(DrawablePtr pDraw)
>      if (pPriv == NULL)
>          return NULL;
>  
> +    if (!AddResource(pDraw->id, dri2DrawableRes, pPriv)) {
> +        free(pPriv);
> +        return NULL;
> +    }
> +
>      pPriv->dri2_screen = ds;
>      pPriv->drawable = pDraw;
>      pPriv->width = pDraw->width;

Newp. If AddResource fails it'll call DRI2DrawableGone for you, which
means in the absolute best case you'd double-free. Since you haven't
initialized any of pPriv at this point hell knows precisely what will
explode, but it'll be something.

>      ref = malloc(sizeof *ref);
>      if (ref == NULL)
>          return BadAlloc;
>  
> -    if (!AddResource(dri2_id, dri2DrawableRes, pPriv)) {
> +    if (!AddResource(pid, dri2ReferenceRes, ref)) {
>          free(ref);
>          return BadAlloc;
>      }

Same deal here, although here you're forgiven for the double-free since
it was already there.

- ajax


More information about the xorg-devel mailing list