From 84925209c9845bdd04d4602b463c11183e9b1a59 Mon Sep 17 00:00:00 2001 From: Brad Hubbard Date: Wed, 14 Mar 2018 13:55:03 +1000 Subject: [PATCH] log: Fix AddressSanitizer: new-delete-type-mismatch If you directly call the operator new function, you must also directly call the operator delete function, and must manually call the destructor as well. Fixes: http://tracker.ceph.com/issues/23324 Signed-off-by: Brad Hubbard (cherry picked from commit 0fe0c1173b1b3efcb407c22e736d0e2d94bf5840) Conflicts: src/log/Entry.h: Resolved for Entry destructor --- src/log/Entry.h | 13 +++++++++++++ src/log/EntryQueue.h | 2 +- src/log/Log.cc | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/log/Entry.h b/src/log/Entry.h index 1b589e1b325cd..31e883c077758 100644 --- a/src/log/Entry.h +++ b/src/log/Entry.h @@ -58,6 +58,10 @@ struct Entry { } } +private: + ~Entry() = default; + +public: // function improves estimate for expected size of message void hint_size() { if (m_exp_len != NULL) { @@ -91,6 +95,15 @@ struct Entry { int snprintf(char* dst, size_t avail) const { return m_streambuf.snprintf(dst, avail); } + + void destroy() { + if (m_exp_len != NULL) { + this->~Entry(); + ::operator delete(this); + } else { + delete(this); + } + } }; } diff --git a/src/log/EntryQueue.h b/src/log/EntryQueue.h index d125540c43b52..4b90b1e8aa2a2 100644 --- a/src/log/EntryQueue.h +++ b/src/log/EntryQueue.h @@ -59,7 +59,7 @@ struct EntryQueue { Entry *t; while (m_head) { t = m_head->m_next; - delete m_head; + m_head->destroy(); m_head = t; } } diff --git a/src/log/Log.cc b/src/log/Log.cc index 3119b013d5be7..39164eb8761a5 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -281,7 +281,7 @@ void Log::flush() // trim while (m_recent.m_len > m_max_recent) { - delete m_recent.dequeue(); + m_recent.dequeue()->destroy(); } m_flush_mutex_holder = 0; -- 2.39.5