From: Abhay Agarwal Date: Tue, 1 Oct 2019 11:31:26 +0000 (+0900) Subject: Free the unused memory for sensor info struct X-Git-Tag: submit/tizen/20191001.125608^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b548f28c1106996fc997b261f2edc1367a887587;p=platform%2Fcore%2Fapi%2Fuser-awareness.git Free the unused memory for sensor info struct This commit fix the issue of memory corruption because of unused memory by ua_sensor_info_s struct and free the memory. Change-Id: I9f8b0bfea9e51f9993b81c79f1e706452a56b40c Signed-off-by: Abhay Agarwal --- diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index 9ada0e1..da60d50 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -335,9 +335,14 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, FUNC_ENTRY; ua_sensor_e bitmask = sensor_info->bitmask; ua_sensor_h sensor_handle; - int ret = ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle); - UA_INFO("ua_device_get_by_device_id returned %s", - _ua_get_error_string(ret)); + int ret; + + ret = ua_sensor_get_by_sensor_info(sensor_info, &sensor_handle); + if (UA_ERROR_NONE != ret) { + UA_INFO("ua_device_get_by_device_id returned %s", + _ua_get_error_string(ret)); + } + switch (monitor->presence_mode) { case UA_DETECT_MODE_ALL_SENSOR: /* diff --git a/src/user-awareness-util.c b/src/user-awareness-util.c index b8ba5fd..e0f33ab 100644 --- a/src/user-awareness-util.c +++ b/src/user-awareness-util.c @@ -272,6 +272,16 @@ static int __ua_update_sensor_info( return UA_ERROR_NONE; } +static void __ua_free_sensor_info(ua_sensor_info_s *sensor_info) +{ + if (NULL != sensor_info) { + if(NULL != sensor_info->values) + g_free(sensor_info->values); + g_free(sensor_info); + } + return; +} + ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info) { FUNC_ENTRY; @@ -325,6 +335,7 @@ int ua_sensor_get_by_sensor_info( ua_sensors_list = g_slist_append(ua_sensors_list, sensor); done: + __ua_free_sensor_info(info); FUNC_EXIT; return ret; }