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>
This commit is contained in:
parent
a44d1f6cc5
commit
f414db7858
2 changed files with 6 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -859,8 +859,10 @@ func (pv *PartViewer) Draw(ctx *ui.Context) {
|
|||
ctx.Printf(0, 0, style, "%s", pv.err.Error())
|
||||
return
|
||||
}
|
||||
if pv.term != nil {
|
||||
pv.term.Draw(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (pv *PartViewer) Cleanup() {
|
||||
if pv.term != nil {
|
||||
|
|
Loading…
Reference in a new issue