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
This commit is contained in:
Maxime Coste 2016-11-23 23:51:16 +00:00
parent b884b499dd
commit 8f2c6eb586

View File

@ -340,7 +340,12 @@ const CommandDesc write_cmd = {
void write_all_buffers()
{
// Copy buffer list because hooks might be creating/deleting buffers
Vector<SafePtr<Buffer>> 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))