From a3eaac65859f97d974b7beb4363dd11d03cebd31 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 14 Jun 2025 10:18:17 +0800 Subject: [PATCH] [gnc-unicode.cpp] fix potential segfault locale was being g_freed prematurely --- libgnucash/core-utils/gnc-unicode.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libgnucash/core-utils/gnc-unicode.cpp b/libgnucash/core-utils/gnc-unicode.cpp index 79f2bef849..55ed179506 100644 --- a/libgnucash/core-utils/gnc-unicode.cpp +++ b/libgnucash/core-utils/gnc-unicode.cpp @@ -169,7 +169,6 @@ unicode_compare_internal(const char* one, const char* two, auto locale{gnc_locale_name()}; std::unique_ptr coll( icu::Collator::createInstance(icu::Locale(locale), status)); - g_free(locale); if (U_SUCCESS(status)) collator_set_strength(coll.get(), strength); @@ -179,6 +178,7 @@ unicode_compare_internal(const char* one, const char* two, g_log(logdomain, G_LOG_LEVEL_ERROR, "Failed to create collator for locale %s: %s", locale, u_errorName(status)); + g_free(locale); return -99; } @@ -189,9 +189,11 @@ unicode_compare_internal(const char* one, const char* two, g_log(logdomain, G_LOG_LEVEL_ERROR, "Comparison of %s and %s in locale %s failed: %s", one, two, locale, u_errorName(status)); + g_free(locale); return -99; } + g_free(locale); return result == UCOL_LESS ? -1 : UCOL_EQUAL ? 0 : 1; }