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 <koni.marti@gmail.com>
This commit is contained in:
parent
71eda7d37c
commit
4782473064
|
@ -106,6 +106,7 @@ type Terminal struct {
|
||||||
damage []vterm.Rect // protected by damageMutex
|
damage []vterm.Rect // protected by damageMutex
|
||||||
damageMutex sync.Mutex
|
damageMutex sync.Mutex
|
||||||
writeMutex sync.Mutex
|
writeMutex sync.Mutex
|
||||||
|
readMutex sync.Mutex
|
||||||
|
|
||||||
OnClose func(err error)
|
OnClose func(err error)
|
||||||
OnEvent func(event tcell.Event) bool
|
OnEvent func(event tcell.Event) bool
|
||||||
|
@ -155,7 +156,9 @@ func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
|
||||||
func (term *Terminal) flushTerminal() {
|
func (term *Terminal) flushTerminal() {
|
||||||
buf := make([]byte, 4096)
|
buf := make([]byte, 4096)
|
||||||
for {
|
for {
|
||||||
|
term.readMutex.Lock()
|
||||||
n, err := term.vterm.Read(buf)
|
n, err := term.vterm.Read(buf)
|
||||||
|
term.readMutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
term.Close(err)
|
term.Close(err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue