memory texture: Fix a memory leak

The callers assumed that gdk_memory_sanitize is transfer full in
both directions, but it wasn't. Make it so.
This commit is contained in:
Matthias Clasen 2024-08-10 22:23:15 -04:00
parent bbb7b365d5
commit d718fda057

View File

@ -111,7 +111,7 @@ gdk_memory_sanitize (GBytes *bytes,
stride % align == 0) stride % align == 0)
{ {
*out_stride = stride; *out_stride = stride;
return g_bytes_ref (bytes); return bytes;
} }
bpp = gdk_memory_format_bytes_per_pixel (format); bpp = gdk_memory_format_bytes_per_pixel (format);
@ -122,6 +122,8 @@ gdk_memory_sanitize (GBytes *bytes,
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
memcpy (copy + y * copy_stride, data + y * stride, bpp * width); memcpy (copy + y * copy_stride, data + y * stride, bpp * width);
g_bytes_unref (bytes);
*out_stride = copy_stride; *out_stride = copy_stride;
return g_bytes_new_take (copy, copy_stride * height); return g_bytes_new_take (copy, copy_stride * height);
} }
@ -197,7 +199,7 @@ gdk_memory_texture_new (int width,
/* needs to be this complex to support subtexture of the bottom right part */ /* needs to be this complex to support subtexture of the bottom right part */
g_return_val_if_fail (g_bytes_get_size (bytes) >= gdk_memory_format_min_buffer_size (format, stride, width, height), NULL); g_return_val_if_fail (g_bytes_get_size (bytes) >= gdk_memory_format_min_buffer_size (format, stride, width, height), NULL);
bytes = gdk_memory_sanitize (bytes, width, height, format, stride, &stride); bytes = gdk_memory_sanitize (g_bytes_ref (bytes), width, height, format, stride, &stride);
self = g_object_new (GDK_TYPE_MEMORY_TEXTURE, self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
"width", width, "width", width,