diff --git a/src/buffer.hh b/src/buffer.hh index 30cc2af9b..80807efe6 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -106,7 +106,7 @@ struct Modification // The Buffer class permits to read and mutate this file // representation. It also manage modifications undo/redo and // provides tools to deal with the line/column nature of text. -class Buffer +class Buffer : public SafeCountable { public: enum class Type diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 77c502886..3aa64aaa6 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -13,7 +13,7 @@ BufferManager::~BufferManager() { // delete remaining buffers while (not m_buffers.empty()) - delete m_buffers.begin()->second; + delete m_buffers.begin()->second.get(); } void BufferManager::register_buffer(Buffer* buffer) @@ -23,7 +23,7 @@ void BufferManager::register_buffer(Buffer* buffer) if (m_buffers.find(name) != m_buffers.end()) throw name_not_unique(); - m_buffers[name] = buffer; + m_buffers[name] = safe_ptr(buffer); } void BufferManager::unregister_buffer(Buffer* buffer) @@ -42,7 +42,7 @@ Buffer* BufferManager::get_buffer(const String& name) if (m_buffers.find(name) == m_buffers.end()) return nullptr; - return m_buffers[name]; + return m_buffers[name].get(); } CandidateList BufferManager::complete_buffername(const String& prefix, diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index beba66529..801989420 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -14,7 +14,7 @@ class Buffer; class BufferManager : public Singleton { public: - typedef std::unordered_map BufferMap; + typedef std::unordered_map> BufferMap; struct iterator : public BufferMap::const_iterator { @@ -23,7 +23,7 @@ public: iterator() {} iterator(const parent_type& other) : parent_type(other) {} Buffer& operator*() const { return *(parent_type::operator*().second); } - Buffer* operator->() const { return parent_type::operator*().second; } + Buffer* operator->() const { return parent_type::operator*().second.get(); } }; ~BufferManager();