From b26d6b61634d3bbdf79db9771f82b4b2cec2a0ee Mon Sep 17 00:00:00 2001
From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com>
Date: Tue, 8 Oct 2024 20:20:12 +0300
Subject: [PATCH 2/2] gtk: Fix memory leaks

Leak fix 1: themes.c:gui_load_theme()

Leak fix 2: pages.c:intro_expose()

Ported to S2_6 by Marko Lindqvist

See RM #931
---
 client/gui-gtk-2.0/pages.c   | 6 ++++--
 client/gui-gtk-3.0/pages.c   | 6 ++++--
 client/gui-gtk-3.0/themes.c  | 2 +-
 client/gui-gtk-3.22/pages.c  | 6 ++++--
 client/gui-gtk-3.22/themes.c | 2 +-
 5 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/client/gui-gtk-2.0/pages.c b/client/gui-gtk-2.0/pages.c
index 2fca9edd73..fd23614873 100644
--- a/client/gui-gtk-2.0/pages.c
+++ b/client/gui-gtk-2.0/pages.c
@@ -160,6 +160,7 @@ static void main_callback(GtkWidget *w, gpointer data)
 static gboolean intro_expose(GtkWidget *w, GdkEventExpose *ev)
 {
   static PangoLayout *layout;
+  PangoFontDescription* desc;
   static int width, height;
   static bool left = FALSE;
 
@@ -168,8 +169,9 @@ static gboolean intro_expose(GtkWidget *w, GdkEventExpose *ev)
     const char *rev_ver;
 
     layout = pango_layout_new(gdk_pango_context_get());
-    pango_layout_set_font_description(layout,
-         pango_font_description_from_string("Sans Bold 10"));
+    desc = pango_font_description_from_string("Sans Bold 10");
+    pango_layout_set_font_description(layout, desc);
+    pango_font_description_free(desc);
 
     rev_ver = fc_git_revision();
 
diff --git a/client/gui-gtk-3.0/pages.c b/client/gui-gtk-3.0/pages.c
index 8c6ed8d673..a10ef6cb85 100644
--- a/client/gui-gtk-3.0/pages.c
+++ b/client/gui-gtk-3.0/pages.c
@@ -161,6 +161,7 @@ static void main_callback(GtkWidget *w, gpointer data)
 static gboolean intro_expose(GtkWidget *w, cairo_t *cr, gpointer *data)
 {
   static PangoLayout *layout;
+  PangoFontDescription* desc;
   static int width, height;
   static bool left = FALSE;
   GtkAllocation allocation;
@@ -174,8 +175,9 @@ static gboolean intro_expose(GtkWidget *w, cairo_t *cr, gpointer *data)
     const char *rev_ver;
 
     layout = pango_layout_new(gtk_widget_create_pango_context(w));
-    pango_layout_set_font_description(layout,
-         pango_font_description_from_string("Sans Bold 10"));
+    desc = pango_font_description_from_string("Sans Bold 10");
+    pango_layout_set_font_description(layout, desc);
+    pango_font_description_free(desc);
 
     rev_ver = fc_git_revision();
 
diff --git a/client/gui-gtk-3.0/themes.c b/client/gui-gtk-3.0/themes.c
index 617d514804..b49ca0d541 100644
--- a/client/gui-gtk-3.0/themes.c
+++ b/client/gui-gtk-3.0/themes.c
@@ -54,7 +54,7 @@ void gui_load_theme(const char *directory, const char *theme_name)
   fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-3.0/gtk.css", directory,
               theme_name);
 
-  gtk_css_provider_load_from_file(fc_css_provider, g_file_new_for_path(buf), &error);
+  gtk_css_provider_load_from_path(fc_css_provider, buf, &error);
 
   if (error) {
     g_warning("%s\n", error->message);
diff --git a/client/gui-gtk-3.22/pages.c b/client/gui-gtk-3.22/pages.c
index a976f13ae8..67953511a0 100644
--- a/client/gui-gtk-3.22/pages.c
+++ b/client/gui-gtk-3.22/pages.c
@@ -161,6 +161,7 @@ static void main_callback(GtkWidget *w, gpointer data)
 static gboolean intro_expose(GtkWidget *w, cairo_t *cr, gpointer *data)
 {
   static PangoLayout *layout;
+  PangoFontDescription* desc;
   static int width, height;
   static bool left = FALSE;
   GtkAllocation allocation;
@@ -174,8 +175,9 @@ static gboolean intro_expose(GtkWidget *w, cairo_t *cr, gpointer *data)
     const char *rev_ver;
 
     layout = pango_layout_new(gtk_widget_create_pango_context(w));
-    pango_layout_set_font_description(layout,
-         pango_font_description_from_string("Sans Bold 10"));
+    desc = pango_font_description_from_string("Sans Bold 10");
+    pango_layout_set_font_description(layout, desc);
+    pango_font_description_free(desc);
 
     rev_ver = fc_git_revision();
 
diff --git a/client/gui-gtk-3.22/themes.c b/client/gui-gtk-3.22/themes.c
index d518b0b741..2301c40d5f 100644
--- a/client/gui-gtk-3.22/themes.c
+++ b/client/gui-gtk-3.22/themes.c
@@ -56,7 +56,7 @@ void gui_load_theme(const char *directory, const char *theme_name)
   fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-3.0/gtk.css", directory,
               theme_name);
 
-  gtk_css_provider_load_from_file(theme_provider, g_file_new_for_path(buf), &error);
+  gtk_css_provider_load_from_path(theme_provider, buf, &error);
 
   if (error != NULL) {
     g_warning("%s\n", error->message);
-- 
2.45.2

