Repository navigation
pasteboard: free native memory in the Linux implementation - #538
Merged
Merged
Conversation
Pasteboard.image did not free the PNG buffer from gdk_pixbuf_save_to_buffer or the FlValue that holds the copy, so each read leaked about two times the image size. Also free the GError, the file paths and their FlValue in Pasteboard.files, and the URI strings when the clipboard clears the data from Pasteboard.writeFiles.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The scoped ownership fixes preserve value lifetimes and use matching cleanup mechanisms, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Fixes native memory leaks in the Linux pasteboard implementation without changing its public API.
Changes:
- Frees image buffers, errors, and temporary values after use.
- Releases file paths and clipboard URI arrays with matching ownership rules.
| File | Description |
|---|---|
| packages/pasteboard/linux/pasteboard_plugin.cc | Corrects memory cleanup for image reads and file clipboard operations. |
Review effort: Balanced
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.
Summary
On Linux,
Pasteboard.imagedid not free the PNG buffer fromgdk_pixbuf_save_to_buffer. It also did not release theFlValuethat holds a copy of that buffer, becausefl_method_call_respond_successdoes not take ownership of the value. Each read leaked about two times the PNG size.The same file has smaller leaks of the same type:
Pasteboard.files: the path fromg_file_get_pathand the stringFlValuepassed tofl_value_append.Pasteboard.writeFiles: the clear callback freed only the array withdelete[], not theg_strconcatstrings. The array now comes fromg_newand the callback frees it withg_strfreev.GErrorfromgdk_pixbuf_save_to_buffer.Evidence
Release build of the example on Linux (sway, Wayland, GTK 3.24.52). The app puts a 1024x1024 image on the clipboard (PNG 3.1 MB), reads
Pasteboard.image10 times to warm up, then reads it 200 times and compares RSS. The test code is not part of this change. The image is set from the same process. Three runs each:After: RSS +2 MB, +4 MB, +0 MB
writeFilesfollowed byfiles200 times returns the correct paths each time after the change.Merge Danger
Door: two-way
Blast Radius: small
Linux only. No API change. Each value is freed after the last use, with the GLib ownership rules for each call.