diff options
author | Mikael Gullstrand <mikael.gullstrand@sonymobile.com> | 2013-05-14 13:15:34 +0200 |
---|---|---|
committer | Johan Redestig <johan.redestig@sonymobile.com> | 2013-06-07 13:56:47 +0200 |
commit | 08bfdd7d88c929964873bb0e311bcae0edb5ebc2 (patch) | |
tree | c9b7ee6f2af01e86241ff913280bdc129e717c85 /luni | |
parent | 0897c6055311bf665365cbb8cae46aadc18d4d45 (diff) | |
download | libcore-08bfdd7d88c929964873bb0e311bcae0edb5ebc2.zip libcore-08bfdd7d88c929964873bb0e311bcae0edb5ebc2.tar.gz libcore-08bfdd7d88c929964873bb0e311bcae0edb5ebc2.tar.bz2 |
Fix memory leaks in org_apache_harmony_xml_ExpatParser
The method expandInternedStringBucket(...) creates a new bucket
but the old bucket is never freed, even though the function doc
claims that it does. To solve this problem the old bucket is
freed when the new one has been created successfully.
Also this commit fixes two possible memory leaks when a
jniThrowOutOfMemoryError is thrown, where the internedString
also needs to be freed.
Change-Id: Ic80a35a2b4ec8f93ddc006aca5609a5ffe74d659
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp index 9b4bb4d..6ba055a 100644 --- a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp +++ b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp @@ -332,6 +332,7 @@ static InternedString** expandInternedStringBucket( memcpy(newBucket, existingBucket, size * sizeof(InternedString*)); newBucket[size] = entry; newBucket[size + 1] = NULL; + delete[] existingBucket; return newBucket; } @@ -385,6 +386,7 @@ static jstring internString(JNIEnv* env, ParsingContext* parsingContext, const c // Expand the bucket. bucket = expandInternedStringBucket(bucket, internedString); if (bucket == NULL) { + delete internedString; jniThrowOutOfMemoryError(env, NULL); return NULL; } @@ -400,6 +402,7 @@ static jstring internString(JNIEnv* env, ParsingContext* parsingContext, const c // Create a new bucket with one entry. bucket = newInternedStringBucket(internedString); if (bucket == NULL) { + delete internedString; jniThrowOutOfMemoryError(env, NULL); return NULL; } |