Fix crashes on multiple file selection in Chrome

Free the jobjects inside the loop. Previously selecting >= 512 files at
same time will cause a crash because the jobjects are not freed.

Bug: 726426
Change-Id: Ie71af5965b76653fa52b8745268aab66db5eff48
Reviewed-on: https://chromium-review.googlesource.com/889498
Reviewed-by: Yaron Friedman <[email protected]>
Reviewed-by: Min Qin <[email protected]>
Commit-Queue: Ran Ji <[email protected]>
Cr-Commit-Position: refs/heads/master@{#532587}
diff --git a/ui/shell_dialogs/select_file_dialog_android.cc b/ui/shell_dialogs/select_file_dialog_android.cc
index 954e19c..5a4fa53 100644
--- a/ui/shell_dialogs/select_file_dialog_android.cc
+++ b/ui/shell_dialogs/select_file_dialog_android.cc
@@ -63,13 +63,16 @@
   jsize length = env->GetArrayLength(filepaths);
   DCHECK(length == env->GetArrayLength(display_names));
   for (int i = 0; i < length; ++i) {
-    std::string path = ConvertJavaStringToUTF8(
+    ScopedJavaLocalRef<jstring> path_ref(
         env, static_cast<jstring>(env->GetObjectArrayElement(filepaths, i)));
-    std::string display_name = ConvertJavaStringToUTF8(
+    base::FilePath file_path =
+        base::FilePath(ConvertJavaStringToUTF8(env, path_ref));
+
+    ScopedJavaLocalRef<jstring> display_name_ref(
         env,
         static_cast<jstring>(env->GetObjectArrayElement(display_names, i)));
-
-    base::FilePath file_path = base::FilePath(path);
+    std::string display_name =
+        ConvertJavaStringToUTF8(env, display_name_ref.obj());
 
     ui::SelectedFileInfo file_info;
     file_info.file_path = file_path;