fix: prevent GBytes leak in GdkPixbufFromSkBitmap on Linux/GTK#49863
Merged
Conversation
Inside gtk_util::GdkPixbufFromSkBitmap, g_bytes_new() was called inline as an argument to gdk_pixbuf_new_from_bytes(), which per GTK docs does not take ownership of the GBytes - it adds its own internal reference. The caller's GBytes* was never stored or unreffed, leaking 4 x width x height bytes of pixel data on every call.
ckerr
approved these changes
Feb 19, 2026
jkleinsc
approved these changes
Feb 20, 2026
|
Congrats on merging your first pull request! 🎉🎉🎉 |
|
Release Notes Persisted
|
This was referenced Feb 20, 2026
Contributor
|
I have automatically backported this PR to "41-x-y", please check out #49895 |
Contributor
|
I have automatically backported this PR to "39-x-y", please check out #49896 |
Contributor
|
I have automatically backported this PR to "38-x-y", please check out #49897 |
Contributor
|
I have automatically backported this PR to "40-x-y", please check out #49898 |
kycutler
pushed a commit
to kycutler/electron
that referenced
this pull request
Feb 26, 2026
…ron#49863) Inside gtk_util::GdkPixbufFromSkBitmap, g_bytes_new() was called inline as an argument to gdk_pixbuf_new_from_bytes(), which per GTK docs does not take ownership of the GBytes - it adds its own internal reference. The caller's GBytes* was never stored or unreffed, leaking 4 x width x height bytes of pixel data on every call.
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.
Description of Change
g_bytes_new()was called inline as an argument togdk_pixbuf_new_from_bytes(), which per GTK docs does not take ownership of theGBytes- it adds its own internal reference. The caller'sGBytes*was never stored or unreffed, leaking4 * width * heightbytes of pixel data on every call.This is most impactful when calling
Tray.setImage()repeatedly (e.g., for animated tray icons), causing continuously growing process memory that is never reclaimed.Internally,
gdk_pixbuf_new_from_bytes()callsg_object_new()with the "pixel-bytes" construct property. Ingdk_pixbuf_set_property(), thePROP_PIXEL_BYTEScase stores the bytes viag_value_dup_boxed(), which callsg_boxed_copy()->_g_type_boxed_copy()-> the registered copy function. SinceG_TYPE_BYTESis registered asG_DEFINE_BOXED_TYPE(GBytes, g_bytes, g_bytes_ref, g_bytes_unref), the copy function isg_bytes_ref(), incrementing therefcount.Simple app that sets tray icon (1024x1024) 100 times:
Before fix:
RSS 633.07 MBAfter fix:
RSS 282.91 MBChecklist
Release Notes
Notes: Fix memory leak when setting icons on Linux/GTK