]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
log: Fix AddressSanitizer: new-delete-type-mismatch 21084/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 14 Mar 2018 03:55:03 +0000 (13:55 +1000)
committerPrashant D <pdhange@redhat.com>
Wed, 28 Mar 2018 02:38:56 +0000 (22:38 -0400)
 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 <bhubbard@redhat.com>
(cherry picked from commit 0fe0c1173b1b3efcb407c22e736d0e2d94bf5840)

Conflicts:
src/log/Entry.h: Resolved for Entry destructor

src/log/Entry.h
src/log/EntryQueue.h
src/log/Log.cc

index 1b589e1b325cd3c2e8fe1b81f8e39c5659733682..31e883c077758cb062b9140a14b6b0fde52279d1 100644 (file)
@@ -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);
+    }
+  }
 };
 
 }
index d125540c43b52ac1a68c6f764f67c54391c78484..4b90b1e8aa2a281f3df54ce15aa3b5018a7f8c7d 100644 (file)
@@ -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;
     }      
   }
index 3119b013d5be7c73f8c0876a60ca69b5058144e3..39164eb8761a52d000270abfa892b151f70e55f4 100644 (file)
@@ -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;