From: saerome.kim Date: Wed, 2 Oct 2019 06:07:58 +0000 (+0900) Subject: Fixed coverity issues X-Git-Tag: submit/tizen/20191002.073539^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01fa75da97a96bc8783b027f4a5b056119ca8060;p=platform%2Fcore%2Fapi%2Fuser-awareness.git Fixed coverity issues 1087645 leaked_storage: Variable sensor_info going out of scope leaks the storage it points to 1087646 var_deref_model: Passing null pointer sensor_info to __send_sensor_presence_event, which dereferences it. 1087649 leaked_storage: Variable sensor_info going out of scope leaks the storage it points to Change-Id: I7c5a080c876c2f43ac3b6ab4fde008bba97894fd Signed-off-by: saerome.kim --- diff --git a/include/user-awareness-util.h b/include/user-awareness-util.h old mode 100644 new mode 100755 index 0fc4555..1534e60 --- a/include/user-awareness-util.h +++ b/include/user-awareness-util.h @@ -241,6 +241,24 @@ int ua_sensor_get_by_sensor_info( ua_sensor_info_s *sensor_info, ua_sensor_h * sensor_handle); +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Releases sensor info. + * @since_tizen 5.5 + * + * @param[in] sensor_info The sensor information to be freed. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * + * @exception + * @pre + * @post + * + */ +int _ua_free_sensor_info(ua_sensor_info_s *sensor_info); + #ifdef __cplusplus } #endif diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec index 8ef4a93..cd1a757 100644 --- a/packaging/capi-network-ua.spec +++ b/packaging/capi-network-ua.spec @@ -1,6 +1,6 @@ Name: capi-network-ua Summary: User Awareness Framework CAPI -Version: 0.10.4 +Version: 0.10.5 Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/user-awareness-device.c b/src/user-awareness-device.c index 4912777..59fee1b 100644 --- a/src/user-awareness-device.c +++ b/src/user-awareness-device.c @@ -238,7 +238,8 @@ ua_ble_payload_s* _ua_get_payload_from_uam(uam_ble_payload_s *uam_payload) return payload; } -void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, ua_ble_payload_s *payload) +void _ua_get_uam_payload_from_ua(uam_ble_payload_s *uam_payload, + ua_ble_payload_s *payload) { FUNC_ENTRY; memset(uam_payload, 0, sizeof(uam_ble_payload_s)); diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c index e5ad298..86baeca 100644 --- a/src/user-awareness-event-handler.c +++ b/src/user-awareness-event-handler.c @@ -34,7 +34,8 @@ extern GSList *ua_devices_db_list; extern GSList *ua_devices_list; /* LCOV_EXCL_START */ -static void __ua_event_handler(int event, uam_event_data_s *event_param, void *user_data) +static void __ua_event_handler(int event, uam_event_data_s *event_param, + void *user_data) { FUNC_ENTRY; @@ -43,7 +44,7 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u switch (event) { case UAM_EVENT_USER_PRESENCE_DETECTED: { uam_detection_event_data_s *event_data = NULL; - uam_sensor_info_s *sensor_info = g_new0(uam_sensor_info_s, 1); + uam_sensor_info_s *sensor_info = NULL; event_data = event_param->data; ret_if(NULL == event_data); @@ -52,6 +53,9 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u ret_if(0 == event_data->timestamp); ret_if(NULL == event_data->device_id); + sensor_info = g_new0(uam_sensor_info_s, 1); + ret_if(NULL == sensor_info); + sensor_info->sensor_bitmask = event_data->sensor_bitmask; _ua_monitor_handle_user_presence_detected( sensor_info, event_data->service, @@ -63,13 +67,16 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u } case UAM_EVENT_USER_ABSENCE_DETECTED: { uam_detection_event_data_s *event_data = NULL; - uam_sensor_info_s *sensor_info = g_new0(uam_sensor_info_s, 1); + uam_sensor_info_s *sensor_info = NULL; event_data = event_param->data; ret_if(NULL == event_data); ret_if(NULL == event_data->service); ret_if(NULL == event_data->account); + sensor_info = g_new0(uam_sensor_info_s, 1); + ret_if(NULL == sensor_info); + sensor_info->sensor_bitmask = event_data->sensor_bitmask; _ua_monitor_handle_user_absence_detected( sensor_info, event_data->service, diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index da60d50..fcbdd77 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -366,7 +366,7 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, if ((monitor->presence_detected_bitmask & bitmask) == 0) if (monitor->presence_cb) monitor->presence_cb(UA_ERROR_NONE, monitor, - bitmask, device_handle, sensor_info, monitor->user_data); + bitmask, device_handle, sensor_handle, monitor->user_data); monitor->presence_detected_bitmask |= bitmask; @@ -728,6 +728,7 @@ void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *info, timestamp, device_id); } } + _ua_free_sensor_info(sensor_info); FUNC_EXIT; } diff --git a/src/user-awareness-util.c b/src/user-awareness-util.c index e0f33ab..415acef 100644 --- a/src/user-awareness-util.c +++ b/src/user-awareness-util.c @@ -272,14 +272,13 @@ static int __ua_update_sensor_info( return UA_ERROR_NONE; } -static void __ua_free_sensor_info(ua_sensor_info_s *sensor_info) +int _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; + retv_if(NULL == sensor_info, UA_ERROR_INVALID_PARAMETER); + g_free(sensor_info->values); + g_free(sensor_info); + + return UA_ERROR_NONE; } ua_sensor_info_s* _uam_to_ua_sensor_info(uam_sensor_info_s *info) @@ -335,7 +334,6 @@ 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; } diff --git a/test/uat-detections.c b/test/uat-detections.c old mode 100644 new mode 100755 index 75a5306..5520970 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -70,7 +70,8 @@ static void __sensor_presence_detected_device(ua_device_h device_handle) g_free(mac); } -static void __sensor_presence_detected_sensor_info(ua_sensor_e sensor, ua_sensor_h sensor_handle) +static void __sensor_presence_detected_sensor_info(ua_sensor_e sensor, + ua_sensor_h sensor_handle) { int ret; char buf[MENU_DATA_SIZE] = {0, }; @@ -172,8 +173,8 @@ static void __sensor_absence_detected_cb(int result, ua_monitor_h monitor, __sensor_presence_detected_sensor_info(sensor, sensor_handle); } -void __ua_test_scan_completed_cb(ua_active_scan_type_e result, ua_monitor_h handle, - ua_device_h device_handle, void *user_data) +void __ua_test_scan_completed_cb(ua_active_scan_type_e result, + ua_monitor_h handle, ua_device_h device_handle, void *user_data) { int ret; if (result == UA_ACTIVE_SCAN_TYPE_DEVICE_FOUND && device_handle) { @@ -342,7 +343,8 @@ static int run_ua_monitor_set_user_absence_condition( msgb("AND [%u] [%s] OR [%u]", bitmask_and, op_value ? "and" : "or", bitmask_or); - ret = ua_monitor_set_user_absence_condition(g_ua_mon_h, bitmask_and, bitmask_or, conjunction_op); + ret = ua_monitor_set_user_absence_condition(g_ua_mon_h, + bitmask_and, bitmask_or, conjunction_op); msg(" - ua_monitor_set_user_absence_condition() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); @@ -611,7 +613,7 @@ static int run_device_power_request_poweroff( } ret = device_power_set_wakeup_reason(POWER_WAKEUP_REASON_REMOTE_CONTROLLER); - if(POWER_ERROR_NONE != device_power_set_wakeup_reason(POWER_WAKEUP_REASON_REMOTE_CONTROLLER)) + if(POWER_ERROR_NONE != ret) { msgr("Fail to set wakeup reason"); return RET_SUCCESS;