From bf904c562107946fcbc00dd3f88916d3422591e9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:35:07 +0900 Subject: [PATCH] sensord: fix memory leak in virtual sensors * event memory has to be not released when error happens Change-Id: I53fe2d366069b773b6d9b05c052fa9ac56f85e0d Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 4 +++- src/sensor/gravity/gravity_sensor.cpp | 3 +++ src/sensor/linear_accel/linear_accel_sensor.cpp | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 3afd961..0c4888a 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -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; diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 2c39ebf..49ee0fe 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -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; } diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 33d1548..eb50de9 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -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; -- 2.7.4