[cairo] Setting the the same object back [bug pattern]

Owen Taylor otaylor at redhat.com
Sat Jan 15 14:02:48 PST 2005


I noticed that cairo suffers in multiple places from a minor
referencing problem:

====
cairo_status_t
_cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t
*pattern)
{
    if (pattern == NULL)
        return CAIRO_STATUS_NULL_POINTER;

    if (gstate->pattern)
        cairo_pattern_destroy (gstate->pattern);

    gstate->pattern = pattern;
    cairo_pattern_reference (pattern);

    return CAIRO_STATUS_SUCCESS;
}
====

If the current pattern for the gstate is passed in, then it is 
unreferenced before it is referenced again. It's easily solved
by addding a:

 if (gstate->pattern == pattern)
   return CAIRO_STATUS_SUCCESS

or by changing the order of the referencing.

Regards,
					Owen

P.S. - this becomes a lot less likely to be triggered if we make
      _cairo_gstate_current_pattern() return a new reference.
      That doesn't change my opinion about returning 
      a new reference :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050115/ad38b292/attachment.pgp


More information about the cairo mailing list