From a78c2c35099462e4f88113278f3b888f8d186112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:53:33 +0200 Subject: [PATCH] actions: Fix the iteration over a slice under modification in QuitAll() (#2898) --- internal/action/actions.go | 4 +--- internal/buffer/buffer.go | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 2b36795a..74e701f4 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1582,9 +1582,7 @@ func (h *BufPane) QuitAll() bool { } quit := func() { - for _, b := range buffer.OpenBuffers { - b.Close() - } + buffer.CloseOpenBuffers() screen.Screen.Fini() InfoBar.Close() runtime.Goexit() diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 38461fbf..6365cec0 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -430,6 +430,15 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT return b } +// CloseOpenBuffers removes all open buffers +func CloseOpenBuffers() { + for i, buf := range OpenBuffers { + buf.Fini() + OpenBuffers[i] = nil + } + OpenBuffers = OpenBuffers[:0] +} + // Close removes this buffer from the list of open buffers func (b *Buffer) Close() { for i, buf := range OpenBuffers {