]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
log: Fix AddressSanitizer: new-delete-type-mismatch 20998/head
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 14 Mar 2018 03:55:03 +0000 (13:55 +1000)
committerPrashant D <pdhange@redhat.com>
Thu, 22 Mar 2018 02:30:26 +0000 (22:30 -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 default destr Entry

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

index 7e2f83401ae6120f3425f3f40c7d14701a98f10b..bbcd17988b2ed410a75f93850d687bfe74f38620 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 8170dcb11b7c42dd700a13ad96f62775148d4d01..490b6c263a7c24eeaf0e9765466f234d2ef7f981 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 3decbc1b0ef0903035ad0f55eb4ebfb7aefc084c..6af49b4c8cd56fd2a37ecb7f00b37fe215681193 100644 (file)
@@ -280,7 +280,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;