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(); }
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;
}