diff options
| author | 2012-12-11 06:06:25 +0900 | |
|---|---|---|
| committer | 2012-12-12 00:57:57 +0900 | |
| commit | b6ac9e50cf1263979dfbab0430fb0e26d32224cd (patch) | |
| tree | b11b717b8760a544b03e9a4cab5df70391dd7a18 | |
| parent | d692c2c6856072a3ec8bec4550466d15a9fef8d7 (diff) | |
Possible leak in android_emoji_EmojiFactory_newInstance
jchars is not released correctly if factory is NULL.
In addition, unnecessary string conversion removed.
Change-Id: I3ea58391dfe7a96ea6d6ae61bb0867a2d8d49fb0
| -rw-r--r-- | core/jni/android_emoji_EmojiFactory.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/core/jni/android_emoji_EmojiFactory.cpp b/core/jni/android_emoji_EmojiFactory.cpp index a658561b059f..43839972227d 100644 --- a/core/jni/android_emoji_EmojiFactory.cpp +++ b/core/jni/android_emoji_EmojiFactory.cpp @@ -3,8 +3,7 @@ #define LOG_TAG "EmojiFactory_jni" #include <utils/Log.h> -#include <utils/String8.h> -#include <utils/String16.h> +#include <ScopedUtfChars.h> #include "EmojiFactory.h" #include <nativehelper/JNIHelp.h> @@ -125,16 +124,13 @@ static jobject android_emoji_EmojiFactory_newInstance( return NULL; } - const jchar* jchars = env->GetStringChars(name, NULL); - jsize len = env->GetStringLength(name); - String8 str(String16(jchars, len)); + ScopedUtfChars nameUtf(env, name); - EmojiFactory *factory = gCaller->TryCallGetImplementation(str.string()); + EmojiFactory *factory = gCaller->TryCallGetImplementation(nameUtf.c_str()); // EmojiFactory *factory = EmojiFactory::GetImplementation(str.string()); if (NULL == factory) { return NULL; } - env->ReleaseStringChars(name, jchars); return create_java_EmojiFactory(env, factory, name); } @@ -151,8 +147,8 @@ static jobject android_emoji_EmojiFactory_newAvailableInstance( if (NULL == factory) { return NULL; } - String16 name_16(String8(factory->Name())); - jstring jname = env->NewString(name_16.string(), name_16.size()); + + jstring jname = env->NewStringUTF(factory->Name()); if (NULL == jname) { return NULL; } |