[PATCH xserver (v4) 02/10] Create SyncObject base type.

Keith Packard keithp at keithp.com
Mon Dec 6 16:39:04 PST 2010


On Mon, 6 Dec 2010 14:53:16 -0800, James Jones <jajones at nvidia.com> wrote:

> -    if (!AddResource(id, RTCounter, (pointer) pCounter))
> +    if (!(pSync = (SyncObject *)malloc(syncSize)))
> +	return NULL;
> +
> +    if (!AddResource(id, resType, (pointer) pSync))
>      {
> -	free(pCounter);
> +	free(pSync);
>  	return NULL;
>      }

This was wrong before and is still wrong now. AddResource actuall calls the
free function if it fails to add a resource to the database. So, the
correct order is to initialize the whole object, as if it were ready to
be used, then call AddResource and not free anything. Your resource
destroy function must handle the case of a resource which has been
created but never used:

Here's a snippet from AddResource which may be useful:

    res = malloc(sizeof(ResourceRec));
    if (!res)
    {
	(*resourceTypes[type & TypeMask].deleteFunc)(value, id);
	return FALSE;
    }

Other than that, this looks like a fine mechanical transformation of the
original code.

Reviewed-by: Keith Packard <keithp at keithp.com>

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20101206/f3ab32fc/attachment-0001.pgp>


More information about the xorg-devel mailing list