From f414db7858c033c6b7845897c9cde35beff22c87 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Thu, 15 Sep 2022 14:39:04 -0500 Subject: [PATCH] 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 Acked-by: Robin Jarry --- widgets/compose.go | 3 +++ widgets/msgviewer.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/widgets/compose.go b/widgets/compose.go index db83a60..3bb334b 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 a74d693..33b6e72 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() {