Fix crash when deleting buffers in a BufClose hook
This commit is contained in:
parent
82e5346904
commit
22d9ffa63a
|
@ -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)
|
||||||
|
|
1
test/regression/0-crash-on-delete-buffer-BufClose/cmd
Normal file
1
test/regression/0-crash-on-delete-buffer-BufClose/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
test/regression/0-crash-on-delete-buffer-BufClose/in
Normal file
1
test/regression/0-crash-on-delete-buffer-BufClose/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
7
test/regression/0-crash-on-delete-buffer-BufClose/rc
Normal file
7
test/regression/0-crash-on-delete-buffer-BufClose/rc
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
edit -scratch buf1
|
||||||
|
edit -scratch buf2
|
||||||
|
hook buffer BufClose buf2 %{
|
||||||
|
delete-buffer
|
||||||
|
delete-buffer buf1
|
||||||
|
}
|
||||||
|
delete-buffer
|
Loading…
Reference in New Issue
Block a user