On Mon, 6 Dec 2010 14:53:16 -0800, James Jones <[email protected]> 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 <[email protected]>

-- 
[email protected]

Attachment: pgpW52EEn8kSM.pgp
Description: PGP signature

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to