[gnome-shell] st/texture-cache: Heap-allocate saved scales



commit 574ab04e9f2c36625cffae29a9744cd6f1a2f455
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Feb 20 22:51:38 2020 +0100

    st/texture-cache: Heap-allocate saved scales
    
    Otherwise we end up reading random junk later, with the result that
    we fail to evict textures with scaled keys.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/2244

 src/st/st-texture-cache.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index 7f957bff74..bb614c6b43 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -183,7 +183,8 @@ st_texture_cache_init (StTextureCache *self)
                                                            g_str_equal,
                                                            g_free,
                                                            (GDestroyNotify) cairo_surface_destroy);
-  self->priv->used_scales = g_hash_table_new (g_double_hash, g_double_equal);
+  self->priv->used_scales = g_hash_table_new_full (g_double_hash, g_double_equal,
+                                                   g_free, NULL);
   self->priv->outstanding_requests = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                             g_free, NULL);
   self->priv->file_monitors = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
@@ -1082,6 +1083,21 @@ hash_table_remove_with_scales (GHashTable *hash,
     }
 }
 
+static void
+hash_table_insert_scale (GHashTable *hash,
+                         double      scale)
+{
+  double *saved_scale;
+
+  if (g_hash_table_contains (hash, &scale))
+    return;
+
+  saved_scale = g_new (double, 1);
+  *saved_scale = scale;
+
+  g_hash_table_add (hash, saved_scale);
+}
+
 static void
 file_changed_cb (GFileMonitor      *monitor,
                  GFile             *file,
@@ -1443,9 +1459,8 @@ st_texture_cache_load_file_sync_to_cogl_texture (StTextureCache *cache,
 
       if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
         {
-          double resource_scale_double = resource_scale;
           g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), image);
-          g_hash_table_insert (cache->priv->used_scales, &resource_scale_double, &resource_scale_double);
+          hash_table_insert_scale (cache->priv->used_scales, (double)resource_scale);
         }
     }
 
@@ -1492,11 +1507,10 @@ st_texture_cache_load_file_sync_to_cairo_surface (StTextureCache        *cache,
 
       if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
         {
-          double resource_scale_double = resource_scale;
           cairo_surface_reference (surface);
           g_hash_table_insert (cache->priv->keyed_surface_cache,
                                g_strdup (key), surface);
-          g_hash_table_insert (cache->priv->used_scales, &resource_scale_double, &resource_scale_double);
+          hash_table_insert_scale (cache->priv->used_scales, (double)resource_scale);
         }
     }
   else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]