LibWeb: Capture weak this ptr in HTMLTextAreaElement input callback

Fixes GC-leak caused by cycle dependency between input callback and
HTMLTextAreaElement that owns it.
This commit is contained in:
Aliaksandr Kalenik 2024-03-16 11:44:18 +01:00 committed by Tim Flynn
parent 9eb38ce79c
commit e0713376a0
Notes: sideshowbarker 2024-07-17 03:25:24 +09:00
2 changed files with 7 additions and 3 deletions

View file

@ -26,7 +26,11 @@ JS_DEFINE_ALLOCATOR(HTMLTextAreaElement);
HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
, m_input_event_timer(Web::Platform::Timer::create_single_shot(0, [this]() { queue_firing_input_event(); }))
, m_input_event_timer(MUST(Core::Timer::create_single_shot(0, [weak_this = make_weak_ptr()]() {
if (!weak_this)
return;
static_cast<HTMLTextAreaElement*>(weak_this.ptr())->queue_firing_input_event();
})))
{
}