From 1c580574ffecf0fcdaf8f2d275df3a7b8a71397f Mon Sep 17 00:00:00 2001 From: starunvs Date: Wed, 6 Aug 2025 10:56:27 +0800 Subject: [PATCH] fix potential memory leak in mutator Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICRG8X Change-Id: I5803d4d6bdb29a1a7d7f10c10fbd934abb1029f0 Signed-off-by: starunvs --- common_components/heap/collector/heuristic_gc_policy.cpp | 2 +- common_components/mutator/mutator.h | 1 + common_components/mutator/tests/mutator_manager_test.cpp | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common_components/heap/collector/heuristic_gc_policy.cpp b/common_components/heap/collector/heuristic_gc_policy.cpp index f7ee18e4de..bb0e169673 100644 --- a/common_components/heap/collector/heuristic_gc_policy.cpp +++ b/common_components/heap/collector/heuristic_gc_policy.cpp @@ -33,8 +33,8 @@ void StartupStatusManager::OnAppStartup() void HeuristicGCPolicy::Init() { HeapParam &heapParam = BaseRuntime::GetInstance()->GetHeapParam(); -#ifndef PANDA_TARGET_32 heapSize_ = heapParam.heapSize * KB; +#ifndef PANDA_TARGET_32 // 2: only half heapSize used allocate heapSize_ = heapSize_ / 2; #endif diff --git a/common_components/mutator/mutator.h b/common_components/mutator/mutator.h index 69b6ec8f96..b9ce1e9780 100755 --- a/common_components/mutator/mutator.h +++ b/common_components/mutator/mutator.h @@ -50,6 +50,7 @@ public: SatbBuffer::Instance().RetireNode(satbNode_); satbNode_ = nullptr; } + delete holder_; } static Mutator* NewMutator() diff --git a/common_components/mutator/tests/mutator_manager_test.cpp b/common_components/mutator/tests/mutator_manager_test.cpp index 2b6f60b951..94b11a04e6 100755 --- a/common_components/mutator/tests/mutator_manager_test.cpp +++ b/common_components/mutator/tests/mutator_manager_test.cpp @@ -31,6 +31,7 @@ HWTEST_F_L0(MutatorManagerTest, BindMutatorOnly_Test1) { MutatorManager *managerPtr = new MutatorManager(); Mutator mutator; + mutator.Init(); managerPtr->UnbindMutatorOnly(); bool res = managerPtr->BindMutatorOnly(&mutator); ASSERT_TRUE(res); @@ -67,6 +68,7 @@ HWTEST_F_L0(MutatorManagerTest, BindMutator_Test1) localData->buffer = nullptr; MutatorManager *managerPtr = new MutatorManager(); Mutator mutator; + mutator.Init(); managerPtr->BindMutator(mutator); EXPECT_TRUE(localData->buffer != nullptr); -- Gitee