From e57f92b7e90ab85fcc9df91045f8905034aed932 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 19 Jan 2024 12:43:37 -0500 Subject: [PATCH] gpu: Fix texture eviction If we gc a cached texture for which the GdkTexture is still alive, the cached texture object will remain accessible via the render data, so need to make sure not to leave a dangling pointer behind here. --- gsk/gpu/gskgpudevice.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gsk/gpu/gskgpudevice.c b/gsk/gpu/gskgpudevice.c index ef2207d3c5..ae5ef51fce 100644 --- a/gsk/gpu/gskgpudevice.c +++ b/gsk/gpu/gskgpudevice.c @@ -198,8 +198,8 @@ gsk_gpu_cached_texture_free (GskGpuDevice *device, gboolean texture_still_alive; texture_still_alive = g_atomic_pointer_exchange (&self->texture, NULL) != NULL; - g_object_unref (self->image); - + g_clear_object (&self->image); + if (!texture_still_alive) g_free (self); } @@ -655,10 +655,8 @@ gsk_gpu_device_lookup_texture_image (GskGpuDevice *self, if (cache == NULL) cache = g_hash_table_lookup (priv->texture_cache, texture); - if (cache) - { - return g_object_ref (cache->image); - } + if (cache && cache->image) + return g_object_ref (cache->image); return NULL; }