Commit 89a7c021 authored by Ran Ji's avatar Ran Ji Committed by Commit Bot

Free jobjects inside loop

We have limited number of jni local references, leaking jobjects inside
loop may cause local reference table to overflow.

Bug: 726426
Change-Id: I4b1ffc9fcb74d1a78d0415f9d9c79533facb7839
Reviewed-on: https://chromium-review.googlesource.com/895843
Commit-Queue: Ran Ji <ranj@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533744}
parent 88e8ebf9
...@@ -142,8 +142,9 @@ std::vector<base::string16> ConvertJStringArrayToString16Array( ...@@ -142,8 +142,9 @@ std::vector<base::string16> ConvertJStringArrayToString16Array(
if (array) { if (array) {
jsize len = env->GetArrayLength(array); jsize len = env->GetArrayLength(array);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
results.push_back(ConvertJavaStringToUTF16(env, ScopedJavaLocalRef<jstring> j_str(
static_cast<jstring>(env->GetObjectArrayElement(array, i)))); env, static_cast<jstring>(env->GetObjectArrayElement(array, i)));
results.push_back(ConvertJavaStringToUTF16(env, j_str));
} }
} }
return results; return results;
...@@ -939,8 +940,9 @@ ScopedJavaLocalRef<jobject> ChromeBrowserProvider::QueryBookmarkFromAPI( ...@@ -939,8 +940,9 @@ ScopedJavaLocalRef<jobject> ChromeBrowserProvider::QueryBookmarkFromAPI(
if (projection) { if (projection) {
jsize len = env->GetArrayLength(projection); jsize len = env->GetArrayLength(projection);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
std::string name = ConvertJavaStringToUTF8(env, static_cast<jstring>( ScopedJavaLocalRef<jstring> j_name(
env->GetObjectArrayElement(projection, i))); env, static_cast<jstring>(env->GetObjectArrayElement(projection, i)));
std::string name = ConvertJavaStringToUTF8(env, j_name);
history::HistoryAndBookmarkRow::ColumnID id = history::HistoryAndBookmarkRow::ColumnID id =
history::HistoryAndBookmarkRow::GetColumnID(name); history::HistoryAndBookmarkRow::GetColumnID(name);
if (id == history::HistoryAndBookmarkRow::COLUMN_END) { if (id == history::HistoryAndBookmarkRow::COLUMN_END) {
...@@ -1080,8 +1082,9 @@ ScopedJavaLocalRef<jobject> ChromeBrowserProvider::QuerySearchTermFromAPI( ...@@ -1080,8 +1082,9 @@ ScopedJavaLocalRef<jobject> ChromeBrowserProvider::QuerySearchTermFromAPI(
if (projection) { if (projection) {
jsize len = env->GetArrayLength(projection); jsize len = env->GetArrayLength(projection);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
std::string name = ConvertJavaStringToUTF8(env, static_cast<jstring>( ScopedJavaLocalRef<jstring> j_name(
env->GetObjectArrayElement(projection, i))); env, static_cast<jstring>(env->GetObjectArrayElement(projection, i)));
std::string name = ConvertJavaStringToUTF8(env, j_name);
history::SearchRow::ColumnID id = history::SearchRow::ColumnID id =
history::SearchRow::GetColumnID(name); history::SearchRow::GetColumnID(name);
if (id == history::SearchRow::COLUMN_END) { if (id == history::SearchRow::COLUMN_END) {
......
...@@ -95,9 +95,9 @@ PolicyConverter::ConvertJavaStringArrayToListValue( ...@@ -95,9 +95,9 @@ PolicyConverter::ConvertJavaStringArrayToListValue(
std::unique_ptr<base::ListValue> list_value(new base::ListValue()); std::unique_ptr<base::ListValue> list_value(new base::ListValue());
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
jstring str = base::android::ScopedJavaLocalRef<jstring> j_str(
static_cast<jstring>(env->GetObjectArrayElement(array.obj(), i)); env, static_cast<jstring>(env->GetObjectArrayElement(array.obj(), i)));
list_value->AppendString(ConvertJavaStringToUTF8(env, str)); list_value->AppendString(ConvertJavaStringToUTF8(env, j_str));
} }
return list_value; return list_value;
......
...@@ -90,8 +90,9 @@ jboolean FakeServerHelperAndroid::VerifySessions( ...@@ -90,8 +90,9 @@ jboolean FakeServerHelperAndroid::VerifySessions(
const JavaParamRef<jobjectArray>& url_array) { const JavaParamRef<jobjectArray>& url_array) {
std::multiset<std::string> tab_urls; std::multiset<std::string> tab_urls;
for (int i = 0; i < env->GetArrayLength(url_array); i++) { for (int i = 0; i < env->GetArrayLength(url_array); i++) {
jstring s = (jstring)env->GetObjectArrayElement(url_array, i); base::android::ScopedJavaLocalRef<jstring> j_string(
tab_urls.insert(base::android::ConvertJavaStringToUTF8(env, s)); env, static_cast<jstring>(env->GetObjectArrayElement(url_array, i)));
tab_urls.insert(base::android::ConvertJavaStringToUTF8(env, j_string));
} }
fake_server::SessionsHierarchy expected_sessions; fake_server::SessionsHierarchy expected_sessions;
expected_sessions.AddWindow(tab_urls); expected_sessions.AddWindow(tab_urls);
......
...@@ -35,17 +35,20 @@ MidiDeviceAndroid::MidiDeviceAndroid(JNIEnv* env, ...@@ -35,17 +35,20 @@ MidiDeviceAndroid::MidiDeviceAndroid(JNIEnv* env,
jsize num_input_ports = env->GetArrayLength(raw_input_ports.obj()); jsize num_input_ports = env->GetArrayLength(raw_input_ports.obj());
for (jsize i = 0; i < num_input_ports; ++i) { for (jsize i = 0; i < num_input_ports; ++i) {
jobject port = env->GetObjectArrayElement(raw_input_ports.obj(), i); ScopedJavaLocalRef<jobject> j_port(
env, env->GetObjectArrayElement(raw_input_ports.obj(), i));
input_ports_.push_back( input_ports_.push_back(
std::make_unique<MidiInputPortAndroid>(env, port, delegate)); std::make_unique<MidiInputPortAndroid>(env, j_port.obj(), delegate));
} }
ScopedJavaLocalRef<jobjectArray> raw_output_ports = ScopedJavaLocalRef<jobjectArray> raw_output_ports =
Java_MidiDeviceAndroid_getOutputPorts(env, raw_device); Java_MidiDeviceAndroid_getOutputPorts(env, raw_device);
jsize num_output_ports = env->GetArrayLength(raw_output_ports.obj()); jsize num_output_ports = env->GetArrayLength(raw_output_ports.obj());
for (jsize i = 0; i < num_output_ports; ++i) { for (jsize i = 0; i < num_output_ports; ++i) {
jobject port = env->GetObjectArrayElement(raw_output_ports.obj(), i); ScopedJavaLocalRef<jobject> j_port(
output_ports_.push_back(std::make_unique<MidiOutputPortAndroid>(env, port)); env, env->GetObjectArrayElement(raw_output_ports.obj(), i));
output_ports_.push_back(
std::make_unique<MidiOutputPortAndroid>(env, j_port.obj()));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment