summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-06-10 15:15:37 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-06-10 15:15:37 -0700
commit8428e036abf2c57305f623451dbf771fc60eeba6 (patch)
tree2a31f2e840bac84aeff06efa479f22c48fc9a169
parent5517af44913256c565901e084713542b042a31ee (diff)
parenta637eb48690eb253903dd07e037e63f60a2fd6f9 (diff)
downloadframeworks_native-8428e036abf2c57305f623451dbf771fc60eeba6.zip
frameworks_native-8428e036abf2c57305f623451dbf771fc60eeba6.tar.gz
frameworks_native-8428e036abf2c57305f623451dbf771fc60eeba6.tar.bz2
Merge "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." into kraken
-rw-r--r--libs/utils/String8.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/libs/utils/String8.cpp b/libs/utils/String8.cpp
index 636cd83..82776f4 100644
--- a/libs/utils/String8.cpp
+++ b/libs/utils/String8.cpp
@@ -301,8 +301,9 @@ void String8::setTo(const String8& other)
status_t String8::setTo(const char* other)
{
+ const char *newString = allocFromUTF8(other, strlen(other));
SharedBuffer::bufferFromData(mString)->release();
- mString = allocFromUTF8(other, strlen(other));
+ mString = newString;
if (mString) return NO_ERROR;
mString = getEmptyString();
@@ -311,8 +312,9 @@ status_t String8::setTo(const char* other)
status_t String8::setTo(const char* other, size_t len)
{
+ const char *newString = allocFromUTF8(other, len);
SharedBuffer::bufferFromData(mString)->release();
- mString = allocFromUTF8(other, len);
+ mString = newString;
if (mString) return NO_ERROR;
mString = getEmptyString();
@@ -321,8 +323,9 @@ status_t String8::setTo(const char* other, size_t len)
status_t String8::setTo(const char16_t* other, size_t len)
{
+ const char *newString = allocFromUTF16(other, len);
SharedBuffer::bufferFromData(mString)->release();
- mString = allocFromUTF16(other, len);
+ mString = newString;
if (mString) return NO_ERROR;
mString = getEmptyString();
@@ -331,8 +334,9 @@ status_t String8::setTo(const char16_t* other, size_t len)
status_t String8::setTo(const char32_t* other, size_t len)
{
+ const char *newString = allocFromUTF32(other, len);
SharedBuffer::bufferFromData(mString)->release();
- mString = allocFromUTF32(other, len);
+ mString = newString;
if (mString) return NO_ERROR;
mString = getEmptyString();