From c40232d5049790bc3581602d51e6cf144b1e93d5 Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Tue, 9 Mar 2021 01:49:57 -0300 Subject: [PATCH] font: Fix double resource leak in font::pango_text The impacted code path is only executed as part of the implementation of the characters_per_line constraint. According to the Pango documentation, PangoFontMetrics should be released using pango_font_metrics_unref(), and PangoFont should be released using *something* not specified. Existing code, and the documentation for pango_fontset_get_font(), suggests the answer for the latter is g_object_unref(). --- changelog.md | 1 + src/font/text.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index b29f9a560c4f..981350426274 100644 --- a/changelog.md +++ b/changelog.md @@ -21,6 +21,7 @@ ### User interface * Improved the Load dialog when there are no saved games for the current version, and also when there are corrupted files. * Re-added the pop-up when there are no saved games at all (issue #5517). + * Fixed resource leak in the Pango text rendering pipeline when using the characters_per_line constraint. ### WML Engine * Standard Location Filters now support gives_income=yes|no to make it simpler to match villages regardless of owner ### Miscellaneous and Bug Fixes diff --git a/src/font/text.cpp b/src/font/text.cpp index a1fcd88728c4..bf38a58b9ec0 100644 --- a/src/font/text.cpp +++ b/src/font/text.cpp @@ -518,6 +518,9 @@ PangoRectangle pango_text::calculate_size(PangoLayout& layout) const w *= characters_per_line_; maximum_width = ceil(pango_units_to_double(w)); + + pango_font_metrics_unref(m); + g_object_unref(f); } else { maximum_width = maximum_width_; }