Compare commits

...

1 Commits

Author SHA1 Message Date
trop[bot]
1079f3bbfa fix: prevent GBytes leak in GdkPixbufFromSkBitmap on Linux/GTK (#49897)
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.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: redeemer <marcin.probola@gmail.com>
2026-02-21 17:11:52 +01:00

View File

@@ -82,11 +82,13 @@ GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap) {
constexpr GdkColorspace kColorspace = GDK_COLORSPACE_RGB;
constexpr gboolean kHasAlpha = true;
constexpr int kBitsPerSample = 8;
return gdk_pixbuf_new_from_bytes(
g_bytes_new(std::data(bytes), std::size(bytes)), kColorspace, kHasAlpha,
kBitsPerSample, width, height,
GBytes* gbytes = g_bytes_new(std::data(bytes), std::size(bytes));
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_bytes(
gbytes, kColorspace, kHasAlpha, kBitsPerSample, width, height,
gdk_pixbuf_calculate_rowstride(kColorspace, kHasAlpha, kBitsPerSample,
width, height));
g_bytes_unref(gbytes);
return pixbuf;
}
} // namespace gtk_util