diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-09-15 14:39:04 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-09-19 21:25:09 +0200 |
commit | f414db7858c033c6b7845897c9cde35beff22c87 (patch) | |
tree | aa4e5139dc4a3360ece72190adc2f4df731241f9 | |
parent | a44d1f6cc5eae4475221233cd14d5d8fca3d2862 (diff) | |
download | aerc-f414db7858c033c6b7845897c9cde35beff22c87.tar.gz |
terminal: protect calls to terminal methods throughout aerc
A race condition can occur when a PartViewer is closing and also working
on a draw. The closing process sets the terminal to nil, which will
create a panic. This can be tested in development by setting the timer
in the main aerc tick loop to something very low (1 ms for example).
One other unprotected call to terminal exists in the composer widget.
Check that the terminal is not nil before calling methods on it.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | widgets/compose.go | 3 | ||||
-rw-r--r-- | widgets/msgviewer.go | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/widgets/compose.go b/widgets/compose.go index db83a608..3bb334b7 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -812,6 +812,9 @@ func (c *Composer) termEvent(event tcell.Event) bool { } func (c *Composer) termClosed(err error) { + if c.editor == nil { + return + } c.grid.RemoveChild(c.editor) c.review = newReviewMessage(c, err) c.grid.AddChild(c.review).At(3, 0) diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index a74d693f..33b6e729 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -859,7 +859,9 @@ func (pv *PartViewer) Draw(ctx *ui.Context) { ctx.Printf(0, 0, style, "%s", pv.err.Error()) return } - pv.term.Draw(ctx) + if pv.term != nil { + pv.term.Draw(ctx) + } } func (pv *PartViewer) Cleanup() { |