Fix crash when deleting buffers in a BufClose hook

This commit is contained in:
Maxime Coste 2019-11-22 20:29:55 +11:00
parent 82e5346904
commit 22d9ffa63a
4 changed files with 13 additions and 3 deletions

View File

@ -48,15 +48,16 @@ Buffer* BufferManager::create_buffer(String name, Buffer::Flags flags,
void BufferManager::delete_buffer(Buffer& buffer) void BufferManager::delete_buffer(Buffer& buffer)
{ {
auto it = find_if(m_buffers, [&](auto& p) { return p.get() == &buffer; }); auto it = find_if(m_buffers, [&](auto& p) { return p.get() == &buffer; });
kak_assert(it != m_buffers.end()); if (it == m_buffers.end()) // we might be trying to recursively delete this buffer
return;
buffer.on_unregistered();
m_buffer_trash.emplace_back(std::move(*it)); m_buffer_trash.emplace_back(std::move(*it));
m_buffers.erase(it); m_buffers.erase(it);
if (ClientManager::has_instance()) if (ClientManager::has_instance())
ClientManager::instance().ensure_no_client_uses_buffer(buffer); ClientManager::instance().ensure_no_client_uses_buffer(buffer);
buffer.on_unregistered();
} }
Buffer* BufferManager::get_buffer_ifp(StringView name) Buffer* BufferManager::get_buffer_ifp(StringView name)

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,7 @@
edit -scratch buf1
edit -scratch buf2
hook buffer BufClose buf2 %{
delete-buffer
delete-buffer buf1
}
delete-buffer