Free the unused memory for sensor info struct submit/tizen/20191001.125608
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 1 Oct 2019 11:31:26 +0000 (20:31 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Tue, 1 Oct 2019 12:39:17 +0000 (21:39 +0900)
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 <ay.agarwal@samsung.com>
src/user-awareness-monitors.c
src/user-awareness-util.c

index 9ada0e19c0b1db82e5073093215509363ac7ea6c..da60d504bc8ea495bf591c4f3a2a6d91fb5afbde 100644 (file)
@@ -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:
                /*
index b8ba5fdf74e1ee333535b4e983d0e3b50534e70f..e0f33ab3658b4e2ae9aea850825838956223a89c 100644 (file)
@@ -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;
 }