From: Brad Hubbard Date: Wed, 14 Mar 2018 03:55:03 +0000 (+1000) Subject: log: Fix AddressSanitizer: new-delete-type-mismatch X-Git-Tag: v13.1.0~541^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F20930%2Fhead;p=ceph.git 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 --- diff --git a/src/log/Entry.h b/src/log/Entry.h index 0005cdda72eb..e0677ef337ff 100644 --- a/src/log/Entry.h +++ b/src/log/Entry.h @@ -48,6 +48,10 @@ struct Entry { } } +private: + ~Entry() = default; + +public: std::ostream& get_ostream() { return m_streambuf->get_ostream(); } @@ -88,6 +92,15 @@ struct Entry { void finish() { m_streambuf->finish(); } + + 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 8170dcb11b7c..490b6c263a7c 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 8aedf3e4abde..9240751dd122 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -289,7 +289,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;