From e450fa50fc242282551f56b941dc93b9a8a0bcbb Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 13 Apr 2021 15:16:50 -0700 Subject: [PATCH] ICU-21587 Fix memory bug w/ baseName Edge cases not fixed in assign and move assign operator while the locale is long and call setKeywordValue with incorrect keyword/values. --- icu4c/source/common/locid.cpp | 11 +++++++++-- icu4c/source/test/intltest/loctest.cpp | 26 ++++++++++++++++++++++++++ icu4c/source/test/intltest/loctest.h | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 02cd82a7b8e..3c6e5b06690 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -469,14 +469,18 @@ Locale& Locale::operator=(Locale&& other) U_NOEXCEPT { if ((baseName != fullName) && (baseName != fullNameBuffer)) uprv_free(baseName); if (fullName != fullNameBuffer) uprv_free(fullName); - if (other.fullName == other.fullNameBuffer) { + if (other.fullName == other.fullNameBuffer || other.baseName == other.fullNameBuffer) { uprv_strcpy(fullNameBuffer, other.fullNameBuffer); + } + if (other.fullName == other.fullNameBuffer) { fullName = fullNameBuffer; } else { fullName = other.fullName; } - if (other.baseName == other.fullName) { + if (other.baseName == other.fullNameBuffer) { + baseName = fullNameBuffer; + } else if (other.baseName == other.fullName) { baseName = fullName; } else { baseName = other.baseName;