From 7a59a6d758b71f3f100f92ed42fc8c0a18f3b63d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 6 Aug 2015 21:51:44 +0100 Subject: [PATCH] ensure a buffer is not referenced a second time, just before actually deleting it It can happen in certain case that a buffer gets referenced after it gets moved to the trash, for example when it gets deleted during its construction (due to BufCreate hook for example). --- src/buffer_manager.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index e468a0d9..dc4c82bf 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -114,7 +114,16 @@ void BufferManager::backup_modified_buffers() void BufferManager::clear_buffer_trash() { while (not m_buffer_trash.empty()) - delete m_buffer_trash.back().get(); + { + Buffer* buffer = m_buffer_trash.back().get(); + + // 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); + + delete buffer; + } } }