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

Leak fix 1: themes.c:gui_load_theme()

Leak fix 2: pages.c:intro_expose()

Ported to S3_1 by Marko Lindqvist

See RM #931
---
 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 +-
 client/gui-gtk-4.0/pages.c   | 6 ++++--
 client/gui-gtk-4.0/themes.c  | 2 +-
 6 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/client/gui-gtk-3.0/pages.c b/client/gui-gtk-3.0/pages.c
index 3121711b4d..df4919dad9 100644
--- a/client/gui-gtk-3.0/pages.c
+++ b/client/gui-gtk-3.0/pages.c
@@ -164,6 +164,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;
@@ -177,8 +178,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 4bb0419242..61b2d45f9e 100644
--- a/client/gui-gtk-3.0/themes.c
+++ b/client/gui-gtk-3.0/themes.c
@@ -57,7 +57,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 64148b175c..67aa954962 100644
--- a/client/gui-gtk-3.22/pages.c
+++ b/client/gui-gtk-3.22/pages.c
@@ -164,6 +164,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;
@@ -177,8 +178,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 75d6647110..3dc5cbe2d7 100644
--- a/client/gui-gtk-3.22/themes.c
+++ b/client/gui-gtk-3.22/themes.c
@@ -59,7 +59,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);
diff --git a/client/gui-gtk-4.0/pages.c b/client/gui-gtk-4.0/pages.c
index cd10889ada..bd738713e2 100644
--- a/client/gui-gtk-4.0/pages.c
+++ b/client/gui-gtk-4.0/pages.c
@@ -169,6 +169,7 @@ static void intro_expose(GtkDrawingArea *w, cairo_t *cr,
                          int width, int height, gpointer data)
 {
   static PangoLayout *layout;
+  PangoFontDescription* desc;
   static int pwidth, pheight;
   static bool left = FALSE;
   GtkAllocation allocation;
@@ -182,8 +183,9 @@ static void intro_expose(GtkDrawingArea *w, cairo_t *cr,
     const char *rev_ver;
 
     layout = pango_layout_new(gtk_widget_create_pango_context(GTK_WIDGET(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-4.0/themes.c b/client/gui-gtk-4.0/themes.c
index 541650754d..c9102d1b2a 100644
--- a/client/gui-gtk-4.0/themes.c
+++ b/client/gui-gtk-4.0/themes.c
@@ -58,7 +58,7 @@ void gui_load_theme(const char *directory, const char *theme_name)
   fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-4.0/gtk.css", directory,
               theme_name);
 
-  gtk_css_provider_load_from_file(theme_provider, g_file_new_for_path(buf));
+  gtk_css_provider_load_from_path(theme_provider, buf);
 }
 
 /*************************************************************************//**
-- 
2.45.2

