From 60db082fdd8f72bb68923d3f407f2968acb3d358 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 Mar 2019 13:11:23 +0100 Subject: [PATCH] AK: Fix node leak in SinglyLinkedList::take_first(). --- AK/SinglyLinkedList.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h index 34281f2175..022b6f9571 100644 --- a/AK/SinglyLinkedList.h +++ b/AK/SinglyLinkedList.h @@ -19,6 +19,14 @@ public: bool is_empty() const { return !head(); } + inline int size_slow() const + { + int size = 0; + for (auto* node = m_head; node; node = node->next) + ++size; + return size; + } + void clear() { for (auto* node = m_head; node; ) { @@ -37,11 +45,13 @@ public: T take_first() { - ASSERT(head()); + ASSERT(m_head); + auto* prev_head = m_head; T value = first(); if (m_tail == m_head) m_tail = nullptr; m_head = m_head->next; + delete prev_head; return value; }