Retain source Image/Canvas in CanvasPattern so the cairo surface stays valid#2583
Open
iurisilvio wants to merge 1 commit into
Open
Retain source Image/Canvas in CanvasPattern so the cairo surface stays valid#2583iurisilvio wants to merge 1 commit into
iurisilvio wants to merge 1 commit into
Conversation
…s valid Pattern stores a cairo_pattern_t* created from a source Image or Canvas via cairo_pattern_create_for_surface(). The pattern references the cairo surface internally but does not retain the JS source object. If the source is garbage-collected, Canvas::destroySurface() calls cairo_surface_finish(_surface) followed by cairo_surface_destroy(_surface). A finished surface is no longer a valid live backing store for pattern rendering, even if cairo still holds a reference to it via the pattern. The bug is reliably reproducible when finalizers run promptly (e.g. with NAPI_EXPERIMENTAL enabled and node_api_post_finalizer in use); without that path, the source typically survives long enough by accident. Fix: hold a Napi::Reference to the source JS object in Pattern and reset it from Pattern::Finalize(). Fixes Automattic#2579
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2579.
Pattern(the C++ class behindCanvasPattern) stores acairo_pattern_t*created from a sourceImageorCanvas, but it doesn't retain the JS source object. When the source is garbage-collected,Canvas::destroySurface()callscairo_surface_finishfollowed bycairo_surface_destroy— a finished surface is no longer a valid live backing store for pattern rendering, even though the cairo pattern still holds a reference to it.The bug becomes reliably reproducible when finalizers run promptly (e.g. with
NAPI_EXPERIMENTALenabled andnode_api_post_finalizerrunning the finalizer at a safe point); without that path, the source typically survives long enough by accident.Fix: hold a
Napi::Reference<Napi::Object>to the source JS object inPatternand reset it fromPattern::Finalize(). Repro in #2579.