sensord: fix memory leak in virtual sensors 06/64506/1
authorkibak.yoon <kibak.yoon@samsung.com>
Thu, 31 Mar 2016 01:35:07 +0000 (10:35 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 1 Apr 2016 10:41:24 +0000 (19:41 +0900)
* event memory has to be not released when error happens

Change-Id: I53fe2d366069b773b6d9b05c052fa9ac56f85e0d
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/sensor/auto_rotation/auto_rotation_sensor.cpp
src/sensor/gravity/gravity_sensor.cpp
src/sensor/linear_accel/linear_accel_sensor.cpp

index 3afd961..0c4888a 100644 (file)
@@ -181,8 +181,10 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event)
 
        remains = get_data(&rotation_data, &data_length);
 
-       if (remains < 0)
+       if (remains < 0) {
+               free(rotation_event);
                return;
+       }
 
        rotation_event->sensor_id = get_id();
        rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT;
index 2c39ebf..49ee0fe 100644 (file)
@@ -171,6 +171,7 @@ void gravity_sensor::synthesize_rv(const sensor_event_t& event)
        gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
        if (!gravity_event->data) {
                _E("Failed to allocate memory");
+               free(gravity_event);
                return;
        }
 
@@ -226,6 +227,7 @@ void gravity_sensor::synthesize_lowpass(const sensor_event_t& event)
        gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
        if (!gravity_event->data) {
                _E("Failed to allocate memory");
+               free(gravity_event);
                return;
        }
 
@@ -275,6 +277,7 @@ void gravity_sensor::synthesize_fusion(const sensor_event_t& event)
        gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
        if (!gravity_event->data) {
                _E("Failed to allocate memory");
+               free(gravity_event);
                return;
        }
 
index 33d1548..eb50de9 100644 (file)
@@ -141,8 +141,10 @@ void linear_accel_sensor::synthesize(const sensor_event_t& event)
 
                remains = get_data(&linear_accel_data, &data_length);
 
-               if (remains < 0)
+               if (remains < 0) {
+                       free(linear_accel_event);
                        return;
+               }
 
                linear_accel_event->sensor_id = get_id();
                linear_accel_event->event_type = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME;