From 6b8309d9a78b02354d563efc65a272772e101046 Mon Sep 17 00:00:00 2001 From: zbx Date: Wed, 3 Sep 2025 09:54:47 +0800 Subject: [PATCH] Fix EcmaGlobalStorage Memory Leak Issue: ICW39K Signed-off-by: zbx Change-Id: I1a67fb5d87679be42f74d406d5caef2ae8b40326 --- ecmascript/ecma_global_storage.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ecmascript/ecma_global_storage.h b/ecmascript/ecma_global_storage.h index 38e841c81f..2bab31e84f 100644 --- a/ecmascript/ecma_global_storage.h +++ b/ecmascript/ecma_global_storage.h @@ -422,13 +422,13 @@ public: node->SetObject(JSTaggedValue::Undefined().GetRawData()); }; - IterateNodeList(clearWeakNodeCallback, topWeakGlobalNodes_); - IterateNodeList(clearNodeCallback, topXRefGlobalNodes_); - IterateNodeList(clearNodeCallback, topGlobalNodes_); + IterateNodeList(clearWeakNodeCallback, topWeakGlobalNodes_, true); + IterateNodeList(clearNodeCallback, topXRefGlobalNodes_, true); + IterateNodeList(clearNodeCallback, topGlobalNodes_, true); } template - inline void IterateNodeList(Callback callback, NodeList *nodeList) + inline void IterateNodeList(Callback callback, NodeList *nodeList, bool releaseNodeList) { auto *next = nodeList; NodeList *current = nullptr; @@ -437,6 +437,9 @@ public: next = current->GetNext(); ASSERT(current != next); current->IterateUsageGlobal(callback); + if (releaseNodeList) { + allocator_->Delete(current); + } } } @@ -500,17 +503,17 @@ public: template void IterateUsageGlobal(Callback &&callback) { - IterateNodeList(callback, topGlobalNodes_); + IterateNodeList(callback, topGlobalNodes_, false); if (nodeKind_ == NodeKind::UNIFIED_NODE) { return; } - IterateNodeList(callback, topXRefGlobalNodes_); + IterateNodeList(callback, topXRefGlobalNodes_, false); } template void IterateWeakUsageGlobal(Callback callback) { - IterateNodeList(callback, topWeakGlobalNodes_); + IterateNodeList(callback, topWeakGlobalNodes_, false); } ECMAGLOBALSTORAGE_PUBLIC_HYBRID_EXTENSION() -- Gitee