Skip to content

Fix: Heap-use-after-free crash when closing profiles with active triggers#8567

Merged
vadi2 merged 1 commit intoMudlet:developmentfrom
mpconley:fix/heap-use-after-free-in-tbuffer-destructor
Nov 26, 2025
Merged

Fix: Heap-use-after-free crash when closing profiles with active triggers#8567
vadi2 merged 1 commit intoMudlet:developmentfrom
mpconley:fix/heap-use-after-free-in-tbuffer-destructor

Conversation

@mpconley
Copy link
Copy Markdown
Contributor

Brief overview of PR changes/additions

Fixed a heap-use-after-free crash in TBuffer destructor by converting the raw mTagWatchdog pointer to std::unique_ptr<QTimer> and implementing proper copy constructor and copy assignment operator.

Motivation for adding to Mudlet

The crash occurred when closing a profile (e.g., using "Close Profile" menu item on Medievia MUD) that had been actively receiving data and running triggers. The issue was caused by TBuffer objects being copied without properly handling the ownership of the mTagWatchdog QTimer. When temporary TBuffer objects were created during copy operations (like in TConsole::copy()), both the original and copied instances shared the same QTimer pointer. When one instance was destroyed, it deleted the timer, leaving the other with a dangling pointer that caused a crash on subsequent destruction.

AddressSanitizer trace showed:

ERROR: AddressSanitizer: heap-use-after-free on address 0x602000915670
READ of size 8 at 0x602000915670 thread T0
#0 in TBuffer::TBuffer()+0x88
#1 in TBuffer::TBuffer()+0x18
#2 in TMainConsole::~TMainConsole()+0x5a8

The fix ensures each TBuffer instance owns its own QTimer through a unique_ptr, preventing double-deletion and use-after-free errors.

Other info (issues closed, discussion etc)

This resolves crashes that occurred during profile shutdown when the copy() Lua function was used in triggers processing incoming game data.

@mpconley mpconley requested a review from a team as a code owner November 21, 2025 20:57
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Nov 21, 2025

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@mpconley mpconley self-assigned this Nov 21, 2025
@vadi2 vadi2 merged commit d56c6c2 into Mudlet:development Nov 26, 2025
12 checks passed
vadi2 pushed a commit that referenced this pull request Nov 26, 2025
…gers (#8567)

#### Brief overview of PR changes/additions

Fixed a heap-use-after-free crash in TBuffer destructor by converting
the raw `mTagWatchdog` pointer to `std::unique_ptr<QTimer>` and
implementing proper copy constructor and copy assignment operator.

#### Motivation for adding to Mudlet

The crash occurred when closing a profile (e.g., using "Close Profile"
menu item on Medievia MUD) that had been actively receiving data and
running triggers. The issue was caused by TBuffer objects being copied
without properly handling the ownership of the `mTagWatchdog` QTimer.
When temporary TBuffer objects were created during copy operations (like
in `TConsole::copy()`), both the original and copied instances shared
the same QTimer pointer. When one instance was destroyed, it deleted the
timer, leaving the other with a dangling pointer that caused a crash on
subsequent destruction.

AddressSanitizer trace showed:
```
ERROR: AddressSanitizer: heap-use-after-free on address 0x602000915670
READ of size 8 at 0x602000915670 thread T0
#0 in TBuffer::TBuffer()+0x88
#1 in TBuffer::TBuffer()+0x18
#2 in TMainConsole::~TMainConsole()+0x5a8

```

The fix ensures each TBuffer instance owns its own QTimer through a
unique_ptr, preventing double-deletion and use-after-free errors.

#### Other info (issues closed, discussion etc)

This resolves crashes that occurred during profile shutdown when the
copy() Lua function was used in triggers processing incoming game data.

(cherry picked from commit d56c6c2)
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Nov 26, 2025

Cherrypicked into release-4.20 branch.

@mpconley mpconley deleted the fix/heap-use-after-free-in-tbuffer-destructor branch December 17, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants