From 8f2c6eb58659bac11014ca0e58de0e5c85a90ff0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 23 Nov 2016 23:51:16 +0000 Subject: [PATCH] Fix write_all_buffers when BufWrite... hooks create/delete buffers The buffer list can be mutated during iteration, so it is no safe to directly iterate on the BufferManager, we need to first create our own copy of the buffer list. Fixes #935 --- src/commands.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/commands.cc b/src/commands.cc index c16d5dd9..f711a525 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -340,7 +340,12 @@ const CommandDesc write_cmd = { void write_all_buffers() { + // Copy buffer list because hooks might be creating/deleting buffers + Vector> buffers; for (auto& buffer : BufferManager::instance()) + buffers.emplace_back(buffer.get()); + + for (auto& buffer : buffers) { if ((buffer->flags() & Buffer::Flags::File) and buffer->is_modified() and !(buffer->flags() & Buffer::Flags::ReadOnly))