From 3ac90da48e9cd56eb4b392c7f176e9267d146500 Mon Sep 17 00:00:00 2001 From: Pavel Vyssotski Date: Tue, 2 Dec 2014 19:54:50 +0600 Subject: Fix OOM throwing if it happens in finalizer reference (take 2) The Class::Alloc should return null if OOM happened during adding finalizer reference, even if finalizable object is allocated succesfully. Added new more reliable test. Change-Id: Id5fed3bdb16297d6d3a2b14ce62cc305aa703d60 Signed-off-by: Dmitry Petrochenko Signed-off-by: Serguei Katkov Signed-off-by: Pavel Vyssotski --- runtime/mirror/class-inl.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime/mirror') diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h index 599f178cbf..1662ebfe82 100644 --- a/runtime/mirror/class-inl.h +++ b/runtime/mirror/class-inl.h @@ -575,6 +575,10 @@ inline Object* Class::Alloc(Thread* self, gc::AllocatorType allocator_type) { allocator_type, VoidFunctor()); if (add_finalizer && LIKELY(obj != nullptr)) { heap->AddFinalizerReference(self, &obj); + if (UNLIKELY(self->IsExceptionPending())) { + // Failed to allocate finalizer reference, it means that the whole allocation failed. + obj = nullptr; + } } return obj; } -- cgit v1.2.3