Skip to content

Commit ecfd22f

Browse files
committed
fix: thread-safety issue in locale decimal separator initialization
- Change get_decimal_separator() to accept &Locale instead of Locale - Eliminates problematic .clone() that caused stale thread stack memory - Fixes valgrind failures in tests/sort/sort-stale-thread-mem test - More efficient (avoids unnecessary clone operation)
1 parent bea05bb commit ecfd22f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/uucore/src/lib/features/i18n/decimal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use icu_provider::prelude::*;
1212
use crate::i18n::get_numeric_locale;
1313

1414
/// Return the decimal separator for the given locale
15-
fn get_decimal_separator(loc: Locale) -> String {
15+
fn get_decimal_separator(loc: &Locale) -> String {
1616
let data_locale = DataLocale::from(loc);
1717

1818
let request = DataRequest {
@@ -34,7 +34,7 @@ fn get_decimal_separator(loc: Locale) -> String {
3434
pub fn locale_decimal_separator() -> &'static str {
3535
static DECIMAL_SEP: OnceLock<String> = OnceLock::new();
3636

37-
DECIMAL_SEP.get_or_init(|| get_decimal_separator(get_numeric_locale().0.clone()))
37+
DECIMAL_SEP.get_or_init(|| get_decimal_separator(&get_numeric_locale().0))
3838
}
3939

4040
#[cfg(test)]
@@ -45,7 +45,7 @@ mod tests {
4545

4646
#[test]
4747
fn test_simple_separator() {
48-
assert_eq!(get_decimal_separator(locale!("en")), ".");
49-
assert_eq!(get_decimal_separator(locale!("fr")), ",");
48+
assert_eq!(get_decimal_separator(&locale!("en")), ".");
49+
assert_eq!(get_decimal_separator(&locale!("fr")), ",");
5050
}
5151
}

0 commit comments

Comments
 (0)