Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: prevent memory leaks in encode_stream callback and SkPixmap#1200

Merged
Brooooooklyn merged 1 commit intomainfrom
fix/encode-stream-memory-leaks
Feb 5, 2026
Merged

fix: prevent memory leaks in encode_stream callback and SkPixmap#1200
Brooooooklyn merged 1 commit intomainfrom
fix/encode-stream-memory-leaks

Conversation

@Brooooooklyn
Copy link
Owner

@Brooooooklyn Brooooooklyn commented Feb 5, 2026

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]


Note

Low Risk
Behavior is unchanged but touches Rust/C++ FFI memory ownership in the synchronous encode_stream path; 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_stream now uses a stack-allocated SkPixmap and passes it by reference (removing the previous new SkPixmap() allocation that was never freed).

On the Rust side, encode_image_inner now owns and explicitly frees the boxed callback after the synchronous encode_stream call completes, while encode_image_stream_callback borrows 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.

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]>
Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Brooooooklyn Brooooooklyn merged commit c21e2ea into main Feb 5, 2026
40 checks passed
@Brooooooklyn Brooooooklyn deleted the fix/encode-stream-memory-leaks branch February 5, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments