Skip to content

Explicitly retain our reference to the pattern surface's CGLayer

Jonathan Kew requested to merge jfkthame/cairo:cglayer-retain into master

This is a bug that originated in bacbe9bb, afaics.

The test suite doesn't appear to hit this code path, but I believe the current code has the potential for a double-release of the source pattern's CGLayer.

The CGLayer used here is owned by the source pattern surface; if we don't bump its retain count here, then when _cairo_quartz_teardown_state calls CGLayerRelease, we'll be unexpectedly releasing the original pattern's reference.

(An alternative fix would be to put the call to CGLayerRelease inside the !DO_LAYER conditional in the teardown function. But in principle it seems like holding a strong reference is the right thing to do.

FTR, Mozilla's fork of cairo has a slightly different version of this code, where DO_LAYER uses a separate CGLayer field in the drawing state, which the teardown function doesn't attempt to release because it is known not to be owned by the state. So that's another possible approach to fix it.)

Merge request reports