From dab0852529229d5a220778bf3f564b4ad2cd3c1c Mon Sep 17 00:00:00 2001
From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com>
Date: Thu, 3 Oct 2024 18:07:00 +0200
Subject: [PATCH 35/35] gtk: Fix memory leaks

Leak fix 1: themes.c:gui_load_theme()

Leak fix 2: pages.c:intro_expose()

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

diff --git a/client/gui-gtk-3.22/pages.c b/client/gui-gtk-3.22/pages.c
index 945556bc58..504ef5ab62 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 01455ad0c6..9980aeecca 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);
 }
 
 /*************************************************************************//**
diff --git a/client/gui-gtk-5.0/pages.c b/client/gui-gtk-5.0/pages.c
index a434869986..e535ee8841 100644
--- a/client/gui-gtk-5.0/pages.c
+++ b/client/gui-gtk-5.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-5.0/themes.c b/client/gui-gtk-5.0/themes.c
index 6cf607683e..578c564283 100644
--- a/client/gui-gtk-5.0/themes.c
+++ b/client/gui-gtk-5.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

