From d2f4f12f66bc2f632a8a47190fae08ec67c9072e Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 4 Oct 2022 13:06:55 -0500 Subject: [PATCH] compose: avoid double lock in MouseEvent The MouseEvent locks the composer, and also calls FocusEditor which attempts to lock the composer. This results in a deadlock. No need to call FocusEditor which takes a name as parameter and needs to iterate over all editors to find the correct one. We already have the headerEditor object, use it directly. Fixes: bf2bf8c242cb ("compose: prevent out of bounds access") Signed-off-by: Tim Culverhouse Signed-off-by: Robin Jarry --- widgets/compose.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/widgets/compose.go b/widgets/compose.go index ee07d1c..eca7684 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -618,10 +618,13 @@ func (c *Composer) MouseEvent(localX int, localY int, event tcell.Event) { c.Lock() defer c.Unlock() c.grid.MouseEvent(localX, localY, event) - for _, e := range c.focusable { + for i, e := range c.focusable { he, ok := e.(*headerEditor) if ok && he.focused { - c.FocusEditor(he.name) + c.focusable[c.focused].Focus(false) + c.focused = i + c.focusable[c.focused].Focus(true) + return } } }