From dfe3098b1854704f8e70b87503d6b5e8d9579490 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 11 Feb 2016 23:07:42 +0000 Subject: [PATCH] Fix buffer deletion logic 'eval -buffer * db' was failing in certain cases --- src/client_manager.cc | 1 + src/commands.cc | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index d06e7259..f742809d 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -134,6 +134,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer) if (buf.get() != &buffer) { client->context().change_buffer(*buf); + client->set_last_buffer(nullptr); break; } } diff --git a/src/commands.cc b/src/commands.cc index 6304378d..abe95c1c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1288,8 +1288,14 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) func(parser, c); }; if (*bufnames == "*") - for (auto buffer : BufferManager::instance()) + { + // copy buffer list as we might be mutating the buffer list + // in the loop. + Vector> buffers{BufferManager::instance().begin(), + BufferManager::instance().end()}; + for (auto buffer : buffers) context_wrap_for_buffer(*buffer); + } else for (auto& name : split(*bufnames, ',')) context_wrap_for_buffer(BufferManager::instance().get_buffer(name));