mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
AK: Fix node leak in SinglyLinkedList::take_first().
This commit is contained in:
parent
cf250e1245
commit
60db082fdd
Notes:
sideshowbarker
2024-07-19 15:04:31 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/60db082fdd8
1 changed files with 11 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue