From 72dc8e6774b48666d4d09da21a603bd171b68b3e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 2 Mar 2016 13:30:11 +0000 Subject: [PATCH] Ensure ClientManager is always outliving the BufferManager --- src/buffer_manager.cc | 16 ++++++++++++---- src/buffer_manager.hh | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) 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);