Skip to content

Commit 2da6a5f

Browse files
committed
SystemStats (Linux): Fix locale clobbering
This fixes a bug where the wrong locale was being restored when querying locale information.
1 parent a2a9c54 commit 2da6a5f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

modules/juce_core/native/juce_SystemStats_linux.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ static String getCpuInfo (const char* key)
4343

4444
static String getLocaleValue (nl_item key)
4545
{
46-
auto oldLocale = ::setlocale (LC_ALL, "");
47-
auto result = String::fromUTF8 (nl_langinfo (key));
48-
::setlocale (LC_ALL, oldLocale);
49-
return result;
46+
const String oldLocale { ::setlocale (LC_ALL, nullptr) };
47+
const ScopeGuard restore { [oldLocale] { ::setlocale (LC_ALL, oldLocale.toRawUTF8()); } };
48+
49+
::setlocale (LC_ALL, ""); // restore locale from env
50+
return String::fromUTF8 (nl_langinfo (key));
5051
}
5152
#endif
5253

0 commit comments

Comments
 (0)