Skip to content

Commit e071337

Browse files
kalenikaliaksandrtrflynn89
authored andcommitted
LibWeb: Capture weak this ptr in HTMLTextAreaElement input callback
Fixes GC-leak caused by cycle dependency between input callback and HTMLTextAreaElement that owns it.
1 parent 9eb38ce commit e071337

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ JS_DEFINE_ALLOCATOR(HTMLTextAreaElement);
2626

2727
HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
2828
: HTMLElement(document, move(qualified_name))
29-
, m_input_event_timer(Web::Platform::Timer::create_single_shot(0, [this]() { queue_firing_input_event(); }))
29+
, m_input_event_timer(MUST(Core::Timer::create_single_shot(0, [weak_this = make_weak_ptr()]() {
30+
if (!weak_this)
31+
return;
32+
static_cast<HTMLTextAreaElement*>(weak_this.ptr())->queue_firing_input_event();
33+
})))
3034
{
3135
}
3236

Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
#pragma once
1010

11+
#include <LibCore/Timer.h>
1112
#include <LibWeb/ARIA/Roles.h>
1213
#include <LibWeb/DOM/Text.h>
1314
#include <LibWeb/HTML/FormAssociatedElement.h>
1415
#include <LibWeb/HTML/HTMLElement.h>
15-
#include <LibWeb/Platform/Timer.h>
1616
#include <LibWeb/WebIDL/Types.h>
1717

1818
namespace Web::HTML {
@@ -128,7 +128,7 @@ class HTMLTextAreaElement final
128128
JS::GCPtr<DOM::Element> m_inner_text_element;
129129
JS::GCPtr<DOM::Text> m_text_node;
130130

131-
RefPtr<Web::Platform::Timer> m_input_event_timer;
131+
RefPtr<Core::Timer> m_input_event_timer;
132132

133133
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
134134
bool m_dirty_value { false };

0 commit comments

Comments
 (0)