diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index efd0c964..3398be34 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -16,11 +16,21 @@ struct name_not_unique : runtime_error name_not_unique() : runtime_error("buffer name is already in use") {} }; +BufferManager::BufferManager() +{ + kak_assert(ClientManager::has_instance()); +} + BufferManager::~BufferManager() { + kak_assert(ClientManager::has_instance()); + // delete remaining buffers while (not m_buffers.empty()) + { + ClientManager::instance().ensure_no_client_uses_buffer(*m_buffers.front().get()); delete m_buffers.front().get(); + } } void BufferManager::register_buffer(Buffer& buffer) @@ -62,8 +72,7 @@ void BufferManager::delete_buffer(Buffer& buffer) { return p.get() == &buffer; }); kak_assert(it != m_buffers.end()); - if (ClientManager::has_instance()) - ClientManager::instance().ensure_no_client_uses_buffer(buffer); + ClientManager::instance().ensure_no_client_uses_buffer(buffer); m_buffers.erase(it); m_buffer_trash.emplace_back(&buffer); @@ -106,8 +115,7 @@ void BufferManager::clear_buffer_trash() // Do that again, to be tolerant in some corner cases, where a buffer is // deleted during its creation - if (ClientManager::has_instance()) - ClientManager::instance().ensure_no_client_uses_buffer(*buffer); + ClientManager::instance().ensure_no_client_uses_buffer(*buffer); delete buffer; } diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index 014d241e..17388c92 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -16,6 +16,7 @@ public: using BufferList = Vector>; using iterator = BufferList::const_iterator; + BufferManager(); ~BufferManager(); void register_buffer(Buffer& buffer);