File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,17 +5,15 @@ namespace node {
55
66void CppgcWrapperList::Cleanup () {
77 for (auto node : *this ) {
8- CppgcMixin* ptr = node->persistent .Get ();
9- if (ptr != nullptr ) {
8+ if (auto * ptr = node->persistent .Get ()) {
109 ptr->Finalize ();
1110 }
1211 }
1312}
1413
1514void CppgcWrapperList::MemoryInfo (MemoryTracker* tracker) const {
1615 for (auto node : *this ) {
17- CppgcMixin* ptr = node->persistent .Get ();
18- if (ptr != nullptr ) {
16+ if (auto * ptr = node->persistent .Get ()) {
1917 // TODO(addaleax): Add weak edges instead of no edges once
2018 // https://github.com/v8/v8/commit/e37cadf1143a8c5bbe44c0408186b5a26cc23863
2119 // is available for us
@@ -25,16 +23,16 @@ void CppgcWrapperList::MemoryInfo(MemoryTracker* tracker) const {
2523}
2624
2725void CppgcWrapperList::PurgeEmpty () {
28- for (auto weak_it = begin (); weak_it != end ();) {
29- CppgcWrapperListNode* node = *weak_it;
30- auto next_it = ++weak_it;
26+ for (auto it = begin (); it != end (); ) {
27+ CppgcWrapperListNode* node = *it;
28+ ++it; // Advance the iterator BEFORE deletion to avoid dangling references
29+
3130 // The underlying cppgc wrapper has already been garbage collected.
3231 // Remove it from the list.
3332 if (!node->persistent ) {
34- node->persistent .Clear ();
35- delete node;
33+ delete node;
3634 }
37- weak_it = next_it;
3835 }
3936}
37+
4038} // namespace node
You can’t perform that action at this time.
0 commit comments