1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +00:00

AK: Fix node leak in SinglyLinkedList::take_first().

This commit is contained in:
Andreas Kling 2019-03-13 13:11:23 +01:00
parent cf250e1245
commit 60db082fdd

View file

@ -19,6 +19,14 @@ public:
bool is_empty() const { return !head(); } 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() void clear()
{ {
for (auto* node = m_head; node; ) { for (auto* node = m_head; node; ) {
@ -37,11 +45,13 @@ public:
T take_first() T take_first()
{ {
ASSERT(head()); ASSERT(m_head);
auto* prev_head = m_head;
T value = first(); T value = first();
if (m_tail == m_head) if (m_tail == m_head)
m_tail = nullptr; m_tail = nullptr;
m_head = m_head->next; m_head = m_head->next;
delete prev_head;
return value; return value;
} }