Skip to content

Commit 62ffbdc

Browse files
Update cppgc_helpers.cc
1 parent 695f01f commit 62ffbdc

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎src/cppgc_helpers.cc‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ namespace node {
55

66
void 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

1514
void 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

2725
void 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

0 commit comments

Comments
 (0)