From 28fb3a98c57cef6e6a72e72f67d89fb63eda6223 Mon Sep 17 00:00:00 2001 From: Santiago Aboy Solanes Date: Thu, 13 Oct 2022 12:08:36 +0100 Subject: Make sure we delete the dex_pc_list vector We were leaking memory by not destroying it before long jumping. Test: Opened the AOSP calendar app and looked for unreachable memory Bug: 251892250 Change-Id: Ib44613174cfe6e315fa77368a74db1005730ba51 --- runtime/quick_exception_handler.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'runtime/quick_exception_handler.cc') diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc index b9dd3e11b6..eb9b47180f 100644 --- a/runtime/quick_exception_handler.cc +++ b/runtime/quick_exception_handler.cc @@ -219,18 +219,19 @@ void QuickExceptionHandler::FindCatch(ObjPtr exception, } if (GetHandlerMethod() != nullptr) { const DexFile* dex_file = GetHandlerMethod()->GetDexFile(); - DCHECK_GE(handler_dex_pc_list_.size(), 1u); + DCHECK(handler_dex_pc_list_.has_value()); + DCHECK_GE(handler_dex_pc_list_->size(), 1u); int line_number = annotations::GetLineNumFromPC( - dex_file, GetHandlerMethod(), handler_dex_pc_list_.front()); + dex_file, GetHandlerMethod(), handler_dex_pc_list_->front()); // We may have an inlined method. If so, we can add some extra logging. std::stringstream ss; ArtMethod* maybe_inlined_method = visitor.GetMethod(); if (maybe_inlined_method != GetHandlerMethod()) { const DexFile* inlined_dex_file = maybe_inlined_method->GetDexFile(); - DCHECK_GE(handler_dex_pc_list_.size(), 2u); + DCHECK_GE(handler_dex_pc_list_->size(), 2u); int inlined_line_number = annotations::GetLineNumFromPC( - inlined_dex_file, maybe_inlined_method, handler_dex_pc_list_.back()); + inlined_dex_file, maybe_inlined_method, handler_dex_pc_list_->back()); ss << " which ends up calling inlined method " << maybe_inlined_method->PrettyMethod() << " (line: " << inlined_line_number << ")"; } @@ -744,10 +745,13 @@ void QuickExceptionHandler::DoLongJump(bool smash_caller_saves) { handler_method_header_ != nullptr && handler_method_header_->IsNterpMethodHeader()) { // Interpreter procceses one method at a time i.e. not inlining - DCHECK_EQ(handler_dex_pc_list_.size(), 1u) << "We shouldn't have any inlined frames."; + DCHECK(handler_dex_pc_list_.has_value()); + DCHECK_EQ(handler_dex_pc_list_->size(), 1u) << "We shouldn't have any inlined frames."; context_->SetNterpDexPC(reinterpret_cast( - GetHandlerMethod()->DexInstructions().Insns() + handler_dex_pc_list_.front())); + GetHandlerMethod()->DexInstructions().Insns() + handler_dex_pc_list_->front())); } + // Clear the dex_pc list so as not to leak memory. + handler_dex_pc_list_.reset(); context_->DoLongJump(); UNREACHABLE(); } -- cgit v1.2.3-59-g8ed1b