Fix for ASAN Issue: alloc-dealloc mismatch
[platform/core/system/sensord.git] / src / shared / message.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 489ebac..e8fd460
@@ -21,6 +21,8 @@
 
 #include <sensor_log.h>
 #include <atomic>
+#include <memory>
+
 
 using namespace ipc;
 
@@ -31,7 +33,7 @@ static std::atomic<uint64_t> sequence(0);
 message::message(size_t capacity)
 : m_size(0)
 , m_capacity(capacity)
-, m_msg((char *)malloc(sizeof(char) * capacity))
+, m_msg(new(std::nothrow) char[sizeof(char) *capacity])
 , ref_cnt(0)
 {
        m_header.id = sequence++;
@@ -61,7 +63,7 @@ message::message(const void *msg, size_t sz)
 message::message(const message &msg)
 : m_size(msg.m_size)
 , m_capacity(msg.m_capacity)
-, m_msg((char *)malloc(sizeof(char) * msg.m_capacity))
+, m_msg(new(std::nothrow) char[(sizeof(char) * msg.m_capacity)])
 , ref_cnt(0)
 {
        ::memcpy(&m_header, &msg.m_header, sizeof(message_header));
@@ -86,7 +88,7 @@ message::message(int error)
 message::~message()
 {
        if (m_msg && ref_cnt == 0) {
-               free(m_msg);
+               delete [] m_msg;
                m_msg = NULL;
        }
 }