From 2da6a5fb621ff8fd6c606c3fda0ce7c5349f5b13 Mon Sep 17 00:00:00 2001 From: Oli Date: Thu, 23 Oct 2025 12:21:31 +0100 Subject: [PATCH] SystemStats (Linux): Fix locale clobbering This fixes a bug where the wrong locale was being restored when querying locale information. --- modules/juce_core/native/juce_SystemStats_linux.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/juce_core/native/juce_SystemStats_linux.cpp b/modules/juce_core/native/juce_SystemStats_linux.cpp index 241ae07495..4ede6a2de2 100644 --- a/modules/juce_core/native/juce_SystemStats_linux.cpp +++ b/modules/juce_core/native/juce_SystemStats_linux.cpp @@ -43,10 +43,11 @@ static String getCpuInfo (const char* key) static String getLocaleValue (nl_item key) { - auto oldLocale = ::setlocale (LC_ALL, ""); - auto result = String::fromUTF8 (nl_langinfo (key)); - ::setlocale (LC_ALL, oldLocale); - return result; + const String oldLocale { ::setlocale (LC_ALL, nullptr) }; + const ScopeGuard restore { [oldLocale] { ::setlocale (LC_ALL, oldLocale.toRawUTF8()); } }; + + ::setlocale (LC_ALL, ""); // restore locale from env + return String::fromUTF8 (nl_langinfo (key)); } #endif