From 4782473064fa0a712aa1e26333ad175446404a64 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Tue, 11 Jan 2022 12:02:28 +0100 Subject: [PATCH] fix segfault when copy-pasting into compose editor fixes the segmentation fault when copy-pasting a large text into the composer editor. The problem is a concurrent read of the vterm field in the Terminal widget in its flushTerminal() method which can be avoided with a mutex. Fixes: https://todo.sr.ht/~rjarry/aerc/12 Signed-off-by: Koni Marti --- widgets/terminal.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/widgets/terminal.go b/widgets/terminal.go index 2a1afa5..68c9553 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -106,6 +106,7 @@ type Terminal struct { damage []vterm.Rect // protected by damageMutex damageMutex sync.Mutex writeMutex sync.Mutex + readMutex sync.Mutex OnClose func(err error) OnEvent func(event tcell.Event) bool @@ -155,7 +156,9 @@ func NewTerminal(cmd *exec.Cmd) (*Terminal, error) { func (term *Terminal) flushTerminal() { buf := make([]byte, 4096) for { + term.readMutex.Lock() n, err := term.vterm.Read(buf) + term.readMutex.Unlock() if err != nil { term.Close(err) return