From f414db7858c033c6b7845897c9cde35beff22c87 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Thu, 15 Sep 2022 14:39:04 -0500 Subject: 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/msgviewer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'widgets/msgviewer.go') 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() { -- cgit