Skip to content

Commit

Permalink
Fix racy access to _tsfTryRedrawCanvas in TermControl (#10549)
Browse files Browse the repository at this point in the history
Previously `TermControl::Close` destroyed all `ThrottledFunc`s to ensure they're not scheduling any callbacks on the UI thread, as the call to `Close` signals the point at which the `TermControl` isn't part of the UI thread anymore. `_CursorPositionChanged` tried to prevent access to the potentially deallocated `_tsfTryRedrawCanvas` by checking the `std::shared_ptr` for nullability, but since the deallocation happens on the UI thread and the nullability check on a background thread, this check introduced a race condition.

This commit solves the issue by not deallocating any `ThrottledFunc`s anymore and instead checking the `_closing` flag inside the `ThrottledFunc` callback on the UI thread.

Additionally this commit cleans up some antipatterns around the use of `std::optional`.

## PR Checklist
* [x] Closes #10479
* [x] Closes #10302

## Validation Steps Performed

* Opening and closing tabs doesn't crash ✔️
* Printing long text doesn't crash ✔️
* Manual scrolling doesn't crash ✔️
* ^G / the audible bell doesn't crash ✔️
  • Loading branch information
lhecker authored Jul 6, 2021
1 parent 59239e3 commit 83c6bce
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 75 deletions.
Loading

0 comments on commit 83c6bce

Please sign in to comment.