fix: prevent memory leaks in encode_stream callback and SkPixmap#1200
Merged
Brooooooklyn merged 1 commit intomainfrom Feb 5, 2026
Merged
fix: prevent memory leaks in encode_stream callback and SkPixmap#1200Brooooooklyn merged 1 commit intomainfrom
Brooooooklyn merged 1 commit intomainfrom
Conversation
Fix two memory leaks in the image encoding path: 1. Rust callback leak: encode_image_stream_callback used Box::leak(Box::from_raw(...)) which permanently leaked the callback allocation on every invocation. The callback is now borrowed via a raw pointer dereference, and the Box is freed by encode_image_inner after the synchronous encode_stream call returns. 2. C++ SkPixmap leak: skiac_surface_encode_stream heap-allocated a SkPixmap with `new` but never deleted it in any code path. Replaced with a stack-allocated SkPixmap since it is only used within the function scope. Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.
Fix two memory leaks in the image encoding path:
Rust callback leak: encode_image_stream_callback used
Box::leak(Box::from_raw(...)) which permanently leaked the callback
allocation on every invocation. The callback is now borrowed via a
raw pointer dereference, and the Box is freed by encode_image_inner
after the synchronous encode_stream call returns.
C++ SkPixmap leak: skiac_surface_encode_stream heap-allocated a
SkPixmap with
newbut never deleted it in any code path. Replacedwith a stack-allocated SkPixmap since it is only used within the
function scope.
Co-Authored-By: Claude Opus 4.5 [email protected]
Note
Low Risk
Behavior is unchanged but touches Rust/C++ FFI memory ownership in the synchronous
encode_streampath; risk is limited to potential callback lifetime or pointer misuse if the sync assumption ever changes.Overview
Fixes two memory leaks in the image stream encoding path.
On the C++ side,
skiac_surface_encode_streamnow uses a stack-allocatedSkPixmapand passes it by reference (removing the previousnew SkPixmap()allocation that was never freed).On the Rust side,
encode_image_innernow owns and explicitly frees the boxed callback after the synchronousencode_streamcall completes, whileencode_image_stream_callbackborrows the callback from the raw context pointer instead of taking ownership/leaking it across invocations.Written by Cursor Bugbot for commit 9f636b8. This will update automatically on new commits. Configure here.