gnucash stable: [gnc-unicode.cpp] fix potential segfault

Christopher Lam clam at code.gnucash.org
Sat Jun 14 01:54:09 EDT 2025


Updated	 via  https://github.com/Gnucash/gnucash/commit/a3eaac65 (commit)
	from  https://github.com/Gnucash/gnucash/commit/400b7807 (commit)



commit a3eaac65859f97d974b7beb4363dd11d03cebd31
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jun 14 10:18:17 2025 +0800

    [gnc-unicode.cpp] fix potential segfault
    
    locale was being g_freed prematurely

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<icu::Collator> 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;
 }
 



Summary of changes:
 libgnucash/core-utils/gnc-unicode.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)



More information about the gnucash-changes mailing list