]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
log: Fix AddressSanitizer: new-delete-type-mismatch
authorBrad Hubbard <bhubbard@redhat.com>
Wed, 14 Mar 2018 03:55:03 +0000 (13:55 +1000)
committerBrad Hubbard <bhubbard@redhat.com>
Thu, 15 Mar 2018 02:00:31 +0000 (12:00 +1000)
 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>
src/log/Entry.h
src/log/EntryQueue.h
src/log/Log.cc

index 0005cdda72eb13ffb41de20a446d2c0b805cfc49..e0677ef337ffca60b0368c96e8da6aec07f151f9 100644 (file)
@@ -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);
+    }
+  }
 };
 
 }
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 8aedf3e4abde9fa8f3678054c155d001065dc235..9240751dd1228b1989ee45d05010cde42a3d737e 100644 (file)
@@ -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;