From f976a98ad2b7fbf6410a1ef82dd128ee94773122 Mon Sep 17 00:00:00 2001 From: caolili123 Date: Tue, 2 Sep 2025 15:08:25 +0800 Subject: [PATCH] Issue: [Bug]: fix warning https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICVZ7G Signed-off-by: caolili123 --- common_components/heap/space/nonmovable_space.cpp | 4 +--- common_components/heap/space/regional_space.h | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common_components/heap/space/nonmovable_space.cpp b/common_components/heap/space/nonmovable_space.cpp index e5217d3e45..647e4bf4b9 100644 --- a/common_components/heap/space/nonmovable_space.cpp +++ b/common_components/heap/space/nonmovable_space.cpp @@ -128,7 +128,7 @@ uintptr_t NonMovableSpace::Alloc(size_t size, bool allowGC) size_t cellCount = size / sizeof(uint64_t) - 1; RegionList* list = recentMonoSizeRegionList_[cellCount]; std::mutex& listMutex = list->GetListMutex(); - listMutex.lock(); + std::lock_guard lock(listMutex); RegionDesc* headRegion = list->GetHeadRegion(); if (headRegion != nullptr) { addr = headRegion->Alloc(size); @@ -140,7 +140,6 @@ uintptr_t NonMovableSpace::Alloc(size_t size, bool allowGC) RegionDesc* region = regionManager_.TakeRegion(1, RegionDesc::UnitRole::SMALL_SIZED_UNITS, false, allowGC); if (region == nullptr) { - listMutex.unlock(); return 0; } DLOG(REGION, "alloc non-movable region @0x%zx+%zu type %u", region->GetRegionStart(), @@ -154,7 +153,6 @@ uintptr_t NonMovableSpace::Alloc(size_t size, bool allowGC) addr = region->Alloc(size); } DLOG(ALLOC, "alloc non-movable obj 0x%zx(%zu)", addr, size); - listMutex.unlock(); return addr; } diff --git a/common_components/heap/space/regional_space.h b/common_components/heap/space/regional_space.h index 6f541b6d49..d8fcef3838 100644 --- a/common_components/heap/space/regional_space.h +++ b/common_components/heap/space/regional_space.h @@ -54,6 +54,9 @@ protected: void InitRegionPhaseLine(RegionDesc* region) { + if (region == nullptr) { + return; + } GCPhase phase = Mutator::GetMutator()->GetMutatorPhase(); if (phase == GC_PHASE_ENUM || phase == GC_PHASE_MARK || phase == GC_PHASE_REMARK_SATB || phase == GC_PHASE_POST_MARK) { -- Gitee