blob: 4709cd8c37fd52f1f0ba6e3959f7c9e9a903d6b1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
From e450fa50fc242282551f56b941dc93b9a8a0bcbb Mon Sep 17 00:00:00 2001
From: Frank Tang <ftang@chromium.org>
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;
|