diff options
author | Andreas Huber | 2010-06-10 13:14:26 -0500 |
---|---|---|
committer | Alex Ray | 2013-07-30 15:56:53 -0500 |
commit | 10e5da58e4c22f2262f7ec7f82745d9673bed14b (patch) | |
tree | b21495cf78e3c530607c9b9235577d27676eeb12 /libs/utils/String8.cpp | |
parent | ad4f2e59af9fe207056099dc002eb80cacbc0f4f (diff) | |
download | platform-system-core-10e5da58e4c22f2262f7ec7f82745d9673bed14b.tar.gz platform-system-core-10e5da58e4c22f2262f7ec7f82745d9673bed14b.tar.xz platform-system-core-10e5da58e4c22f2262f7ec7f82745d9673bed14b.zip |
Fix String8 to free its memory only after assignment operations based on pointers are finished in case that pointer referred to the string's original contents.
Change-Id: I6961f3cf10ba3b728579ea63262db750a4cf8577
Diffstat (limited to 'libs/utils/String8.cpp')
-rw-r--r-- | libs/utils/String8.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libs/utils/String8.cpp b/libs/utils/String8.cpp index 636cd8342..82776f47a 100644 --- a/libs/utils/String8.cpp +++ b/libs/utils/String8.cpp | |||
@@ -301,8 +301,9 @@ void String8::setTo(const String8& other) | |||
301 | 301 | ||
302 | status_t String8::setTo(const char* other) | 302 | status_t String8::setTo(const char* other) |
303 | { | 303 | { |
304 | const char *newString = allocFromUTF8(other, strlen(other)); | ||
304 | SharedBuffer::bufferFromData(mString)->release(); | 305 | SharedBuffer::bufferFromData(mString)->release(); |
305 | mString = allocFromUTF8(other, strlen(other)); | 306 | mString = newString; |
306 | if (mString) return NO_ERROR; | 307 | if (mString) return NO_ERROR; |
307 | 308 | ||
308 | mString = getEmptyString(); | 309 | mString = getEmptyString(); |
@@ -311,8 +312,9 @@ status_t String8::setTo(const char* other) | |||
311 | 312 | ||
312 | status_t String8::setTo(const char* other, size_t len) | 313 | status_t String8::setTo(const char* other, size_t len) |
313 | { | 314 | { |
315 | const char *newString = allocFromUTF8(other, len); | ||
314 | SharedBuffer::bufferFromData(mString)->release(); | 316 | SharedBuffer::bufferFromData(mString)->release(); |
315 | mString = allocFromUTF8(other, len); | 317 | mString = newString; |
316 | if (mString) return NO_ERROR; | 318 | if (mString) return NO_ERROR; |
317 | 319 | ||
318 | mString = getEmptyString(); | 320 | mString = getEmptyString(); |
@@ -321,8 +323,9 @@ status_t String8::setTo(const char* other, size_t len) | |||
321 | 323 | ||
322 | status_t String8::setTo(const char16_t* other, size_t len) | 324 | status_t String8::setTo(const char16_t* other, size_t len) |
323 | { | 325 | { |
326 | const char *newString = allocFromUTF16(other, len); | ||
324 | SharedBuffer::bufferFromData(mString)->release(); | 327 | SharedBuffer::bufferFromData(mString)->release(); |
325 | mString = allocFromUTF16(other, len); | 328 | mString = newString; |
326 | if (mString) return NO_ERROR; | 329 | if (mString) return NO_ERROR; |
327 | 330 | ||
328 | mString = getEmptyString(); | 331 | mString = getEmptyString(); |
@@ -331,8 +334,9 @@ status_t String8::setTo(const char16_t* other, size_t len) | |||
331 | 334 | ||
332 | status_t String8::setTo(const char32_t* other, size_t len) | 335 | status_t String8::setTo(const char32_t* other, size_t len) |
333 | { | 336 | { |
337 | const char *newString = allocFromUTF32(other, len); | ||
334 | SharedBuffer::bufferFromData(mString)->release(); | 338 | SharedBuffer::bufferFromData(mString)->release(); |
335 | mString = allocFromUTF32(other, len); | 339 | mString = newString; |
336 | if (mString) return NO_ERROR; | 340 | if (mString) return NO_ERROR; |
337 | 341 | ||
338 | mString = getEmptyString(); | 342 | mString = getEmptyString(); |