summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chang Xing <chxing@google.com> 2017-06-08 11:31:48 -0700
committer Chang Xing <chxing@google.com> 2017-06-08 11:44:00 -0700
commit443f8628acaf1308802cbc21865bcfd38dce8b4d (patch)
tree2f9f939cdd7bc2c1f4f0b8ce08c0c83924073a42
parent83b140474aa1759739c8ee4464bf226c4fa0f6d7 (diff)
Fix local reference leak under reflection.
Checks fail caused by a local reference leak when reflection throwns an exception which prevents GC to prune classes during initialization. Fixed by use ScopedLocalRef to release the resource after using. Test: test-art-host Change-Id: Ife160cfb768497ab3d6d1ca9686da0d6bc3281fb
-rw-r--r--runtime/reflection.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index e16ef1d77c..532da2b16e 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -31,6 +31,7 @@
#include "nth_caller_visitor.h"
#include "scoped_thread_state_change-inl.h"
#include "stack_reference.h"
+#include "ScopedLocalRef.h"
#include "well_known_classes.h"
namespace art {
@@ -668,7 +669,7 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
// Wrap any exception with "Ljava/lang/reflect/InvocationTargetException;" and return early.
if (soa.Self()->IsExceptionPending()) {
// If we get another exception when we are trying to wrap, then just use that instead.
- jthrowable th = soa.Env()->ExceptionOccurred();
+ ScopedLocalRef<jthrowable> th(soa.Env(), soa.Env()->ExceptionOccurred());
soa.Self()->ClearException();
jclass exception_class = soa.Env()->FindClass("java/lang/reflect/InvocationTargetException");
if (exception_class == nullptr) {
@@ -677,7 +678,7 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
}
jmethodID mid = soa.Env()->GetMethodID(exception_class, "<init>", "(Ljava/lang/Throwable;)V");
CHECK(mid != nullptr);
- jobject exception_instance = soa.Env()->NewObject(exception_class, mid, th);
+ jobject exception_instance = soa.Env()->NewObject(exception_class, mid, th.get());
if (exception_instance == nullptr) {
soa.Self()->AssertPendingException();
return nullptr;