Free native resources on three rare decoder error paths#2587
Open
iurisilvio wants to merge 1 commit into
Open
Conversation
- Image::loadGIFFromBuffer: delete[] the decode buffer before returning CAIRO_STATUS_READ_ERROR when neither a local nor a global color map exists. The full width*height*4 buffer was previously dropped. - Image::assignDataAsMime: capture the cairo_surface_set_mime_data return status; on non-success, reverse the AdjustExternalMemory(env, len) and free both mime_data (a copy of the JPEG buffer) and mime_closure, which cairo never takes ownership of in the failure case. - create_transparent_pattern: destroy mask_context and mask_surface before returning NULL when cairo_create reports an error status (cairo OOM). All three are real ownership bugs but sit behind error/OOM gates that aren't reachable in normal operation, so there's no measurable RSS slope to attach. Bundled because each is a one- or two-line fix in the same family. Fixes Automattic#2586
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 #2586.
Three small ownership bugs on rare error paths in image decoders and pattern construction. None are reachable in normal operation, but each is a real leak when its gate fires.
Changes
Image::loadGIFFromBuffer:delete[]the decode buffer before returningCAIRO_STATUS_READ_ERRORwhen neither a local nor a global color map exists. Per-occurrence leak is the fullwidth * height * 4buffer.Image::assignDataAsMime: capture thecairo_surface_set_mime_datareturn status; on non-success, reverse theNapi::MemoryManagement::AdjustExternalMemory(env, len)andfreebothmime_data(a copy of the JPEG buffer) andmime_closure. Cairo doesn't take ownership in the failure case and never callsclearMimeData, so both allocations otherwise live forever.create_transparent_pattern: destroymask_contextandmask_surfacebefore returningNULLwhencairo_createreports an error status. Only reachable on cairo OOM.Verification
These are behind error/OOM gates that aren't reachable from JS without poking at internals, so no RSS reproduction is attached. The fixes are visible by inspection and total +12 / -1 lines.