[Non-ACR][Fix for TFIVE-11871] 57/182857/8
authorSudipto <sudipto.bal@samsung.com>
Thu, 28 Jun 2018 09:55:02 +0000 (15:25 +0530)
committerSudipto <sudipto.bal@samsung.com>
Tue, 14 Aug 2018 10:23:08 +0000 (15:53 +0530)
Change-Id: Ief91ed874a9af2c3793dbf07689b08aed8363246
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
src/server/sensor_handler.cpp

index 37c4dc2..fcfef69 100644 (file)
@@ -98,12 +98,15 @@ uint32_t sensor_handler::observer_count(void)
 
 void sensor_handler::set_cache(sensor_data_t *data, int size)
 {
-       if (m_last_data == NULL) {
-               m_last_data = (sensor_data_t*)malloc(size);
+       retm_if(data == NULL, "Nothing to copy from as source is NULL");
+       retm_if(size <= 0, "data is of size 0");
+
+       if (m_last_data_size != size) {
+               m_last_data = (sensor_data_t*)realloc(m_last_data, size);
                retm_if(m_last_data == NULL, "Memory allocation failed");
+               m_last_data_size = size;
        }
 
-       m_last_data_size = size;
        memcpy(m_last_data, data, size);
 }