[gnome-shell/gnome-41] shell/window-preview-layout: Fix memory leaks



commit 0f2f658d53c011ae44e4a8578805924899b8b582
Author: Sebastian Keller <skeller gnome org>
Date:   Mon Mar 21 20:45:36 2022 +0100

    shell/window-preview-layout: Fix memory leaks
    
    The WindowInfo allocated when adding a window was not getting free'd
    when the window was getting removed again or the layout was getting
    disposed. Also the hash table in which the WindowInfos are stored was
    not getting free'd on destruction either. Both could result in small
    leaks after closing the overview.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5238
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2256>
    (cherry picked from commit 8c40b48a0951d18776daa08dee8b537d5029f338)

 src/shell-window-preview-layout.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/shell-window-preview-layout.c b/src/shell-window-preview-layout.c
index a759a74f17..0627264093 100644
--- a/src/shell-window-preview-layout.c
+++ b/src/shell-window-preview-layout.c
@@ -292,6 +292,19 @@ shell_window_preview_layout_dispose (GObject *gobject)
   G_OBJECT_CLASS (shell_window_preview_layout_parent_class)->dispose (gobject);
 }
 
+static void
+shell_window_preview_layout_finalize (GObject *gobject)
+{
+  ShellWindowPreviewLayout *self = SHELL_WINDOW_PREVIEW_LAYOUT (gobject);
+  ShellWindowPreviewLayoutPrivate *priv;
+
+  priv = shell_window_preview_layout_get_instance_private (self);
+
+  g_hash_table_destroy (priv->windows);
+
+  G_OBJECT_CLASS (shell_window_preview_layout_parent_class)->finalize (gobject);
+}
+
 static void
 shell_window_preview_layout_init (ShellWindowPreviewLayout *self)
 {
@@ -299,7 +312,8 @@ shell_window_preview_layout_init (ShellWindowPreviewLayout *self)
 
   priv = shell_window_preview_layout_get_instance_private (self);
 
-  priv->windows = g_hash_table_new (NULL, NULL);
+  priv->windows = g_hash_table_new_full (NULL, NULL, NULL,
+                                         (GDestroyNotify) g_free);
 }
 
 static void
@@ -314,6 +328,7 @@ shell_window_preview_layout_class_init (ShellWindowPreviewLayoutClass *klass)
   layout_class->set_container = shell_window_preview_layout_set_container;
 
   gobject_class->dispose = shell_window_preview_layout_dispose;
+  gobject_class->finalize = shell_window_preview_layout_finalize;
   gobject_class->get_property = shell_window_preview_layout_get_property;
 
   /**


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