Skip to content

Commit

Permalink
Debugger plugin: Clean up event listeners before the plugin is delete…
Browse files Browse the repository at this point in the history
…d to avoid use-after-free, fixes #322. (#323)
  • Loading branch information
LoneBoco authored Jun 8, 2022
1 parent 89a357b commit 961747e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Source/Debugger/DebuggerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ bool DebuggerPlugin::LoadLogElement()

void DebuggerPlugin::ReleaseElements()
{
// Erase event listeners to prevent crashes.
if (debug_context && info_element)
{
debug_context->RemoveEventListener("click", info_element, true);
debug_context->RemoveEventListener("mouseover", info_element, true);
}

if (host_context)
{
if (menu_element)
Expand All @@ -395,6 +402,10 @@ void DebuggerPlugin::ReleaseElements()
application_interface = nullptr;
log_interface.reset();
}

// Update to release documents before the plugin gets deleted.
// Helps avoid cleanup crashes.
host_context->Update();
}

if (debug_context)
Expand All @@ -404,6 +415,10 @@ void DebuggerPlugin::ReleaseElements()
debug_context->UnloadDocument(hook_element);
hook_element = nullptr;
}

// Update to release documents before the plugin gets deleted.
// Helps avoid cleanup crashes.
debug_context->Update();
}
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Debugger/ElementInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ ElementInfo::ElementInfo(const String& tag) : ElementDocument(tag)

ElementInfo::~ElementInfo()
{
RemoveEventListener(EventId::Click, this);
RemoveEventListener(EventId::Mouseover, this);
RemoveEventListener(EventId::Mouseout, this);
}

// Initialises the info element.
Expand Down
12 changes: 12 additions & 0 deletions Source/Debugger/ElementLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ ElementLog::ElementLog(const String& tag) : ElementDocument(tag)

ElementLog::~ElementLog()
{
RemoveEventListener(EventId::Click, this);

if (beacon && beacon->GetFirstChild())
{
beacon->GetFirstChild()->RemoveEventListener(EventId::Click, this);
beacon->GetParentNode()->RemoveChild(beacon);
}

if (message_content)
{
message_content->RemoveEventListener(EventId::Resize, this);
}
}

// Initialises the log element.
Expand Down

0 comments on commit 961747e

Please sign in to comment.