From a88b90a69df499b8c9ce350212288638ab5f2865 Mon Sep 17 00:00:00 2001 From: Loko Kung Date: Thu, 17 Nov 2022 22:35:24 +0000 Subject: [PATCH] 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 Auto-Submit: Loko Kung Commit-Queue: Loko Kung Kokoro: Kokoro --- src/dawn/common/LinkedList.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/dawn/common/LinkedList.h b/src/dawn/common/LinkedList.h index c196098107..b0f990fccb 100644 --- a/src/dawn/common/LinkedList.h +++ b/src/dawn/common/LinkedList.h @@ -116,6 +116,12 @@ class LinkNode { } } + ~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* e) { this->next_ = e; @@ -175,13 +181,6 @@ class LinkedList { // 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* e) { e->InsertBefore(&root_); }