Remove ListNode from any LinkedList in dtor.
- Issue found in LinkedListTests when running against ASAN since the
LinkedList was being destroyed after the Nodes, thereby triggering
a RemoveFromList on the root node, but the other nodes were never
removed from the list and are dangling pointers.
Change-Id: I136abbc5d73c35142990c9fe4669e5fc6d5ef644
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110500
Reviewed-by: Austin Eng <enga@chromium.org>
Auto-Submit: Loko Kung <lokokung@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/common/LinkedList.h b/src/dawn/common/LinkedList.h
index c196098..b0f990f 100644
--- a/src/dawn/common/LinkedList.h
+++ b/src/dawn/common/LinkedList.h
@@ -116,6 +116,12 @@
}
}
+ ~LinkNode() {
+ // Remove the node from any list, otherwise there can be outstanding references to the node
+ // even after it has been freed.
+ RemoveFromList();
+ }
+
// Insert |this| into the linked list, before |e|.
void InsertBefore(LinkNode<T>* e) {
this->next_ = e;
@@ -175,13 +181,6 @@
// and root_->previous() wraps around to the end of the list).
LinkedList() : root_(&root_, &root_) {}
- ~LinkedList() {
- // If any LinkNodes still exist in the LinkedList, there will be outstanding references to
- // root_ even after it has been freed. We should remove root_ from the list to prevent any
- // future access.
- root_.RemoveFromList();
- }
-
// Appends |e| to the end of the linked list.
void Append(LinkNode<T>* e) { e->InsertBefore(&root_); }