OSDN Git Service

Put a handle on the String object.
authorNicolas Geoffray <ngeoffray@google.com>
Tue, 3 May 2016 13:04:02 +0000 (14:04 +0100)
committerNicolas Geoffray <ngeoffray@google.com>
Wed, 4 May 2016 08:43:22 +0000 (09:43 +0100)
Otherwise, a GC could occur in the loop below, and the String
be moved (note that there was already one for the Class object to
protect for that same problem).

bug:27561834

(cherry picked from commit a96f316f6f0526c91c6c102a267df6b1e4df39da)

Change-Id: I89c093dd67982abb3502975097a337c7e3816360

runtime/native/java_lang_Class.cc

index 6b7ca40..0624da3 100644 (file)
@@ -238,12 +238,13 @@ static mirror::Field* GetPublicFieldRecursive(
   DCHECK(name != nullptr);
   DCHECK(self != nullptr);
 
-  StackHandleScope<1> hs(self);
+  StackHandleScope<2> hs(self);
   MutableHandle<mirror::Class> h_clazz(hs.NewHandle(clazz));
+  Handle<mirror::String> h_name(hs.NewHandle(name));
 
   // We search the current class, its direct interfaces then its superclass.
   while (h_clazz.Get() != nullptr) {
-    mirror::Field* result = GetDeclaredField(self, h_clazz.Get(), name);
+    mirror::Field* result = GetDeclaredField(self, h_clazz.Get(), h_name.Get());
     if ((result != nullptr) && (result->GetAccessFlags() & kAccPublic)) {
       return result;
     } else if (UNLIKELY(self->IsExceptionPending())) {
@@ -258,7 +259,7 @@ static mirror::Field* GetPublicFieldRecursive(
         self->AssertPendingException();
         return nullptr;
       }
-      result = GetPublicFieldRecursive(self, iface, name);
+      result = GetPublicFieldRecursive(self, iface, h_name.Get());
       if (result != nullptr) {
         DCHECK(result->GetAccessFlags() & kAccPublic);
         return result;