Fixed the Coverity & Svace issues.
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 26 Aug 2019 08:57:21 +0000 (17:57 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 26 Aug 2019 11:00:23 +0000 (20:00 +0900)
1078724 Leaked_storage: Variable mac going out of scope leaks the storage it points to.
1078723 copy_paste_error: g_presence_and_cond looks like a copy-paste error.
1078720 Check return: Calling ua_device_get_mac_address without checking return value.
1078717 Check_return:Calling ua_device_get_mac_type without checking return value.
1076181 Leaked_storage: Variable service going out of scope leaks the storage it points to.
1076152 Leaked_storage: Variable service going out of scope leaks the storage it points to.
405915 Leaked_storage: Variable mac going out of scope leaks the storage it points to

Change-Id: I1c8d80568c0df9901abcdc0c26a5318b7faa3a6b
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
packaging/capi-network-ua.spec
src/user-awareness-monitors.c
test/uat-detections.c
test/uat-init.c

index 8edc80e9411071e32dbe8bd40317abbd46067c18..47b1e11df955f1b2e745e33ee71cec4291d59d2f 100644 (file)
@@ -1,6 +1,6 @@
 Name: capi-network-ua
 Summary: User Awareness Framework CAPI
-Version: 0.6.9
+Version: 0.6.10
 Release: 1
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
index 7e9dd353161bd7dce59b7fed63c13043d03a2407..5a0b317b05764d64a4c60423fe908964f2084893 100644 (file)
@@ -698,6 +698,8 @@ int ua_monitor_start_presence_detection(
        monitor->user_data = user_data;
        monitor->presence_detection_started = TRUE;
 
+       g_free(service);
+
        FUNC_EXIT;
        return UA_ERROR_NONE;
 }
@@ -729,8 +731,10 @@ int ua_monitor_start_absence_detection(
 
        if (monitor->service)
                if ((service && g_strcmp0(monitor->service, service)) ||
-                               (!service && g_strcmp0(monitor->service, UA_SERVICE_DEFAULT)))
+                       (!service && g_strcmp0(monitor->service, UA_SERVICE_DEFAULT))) {
+                       g_free(service);
                        return UA_ERROR_NOT_PERMITTED;
+               }
 
        retv_if(UA_DETECT_MODE_INVALID <= mode, UA_ERROR_INVALID_PARAMETER);
        retv_if(0 == monitor->sensor_bitmask, UA_ERROR_NO_DATA);
@@ -767,6 +771,8 @@ int ua_monitor_start_absence_detection(
        monitor->user_data = user_data;
        monitor->absence_detection_started = TRUE;
 
+       g_free(service);
+
        FUNC_EXIT;
        return UA_ERROR_NONE;
 }
index 7af64d19235a7a20eb6b8b06c07642657c6bcb61..6242e70b9c99b854cfebbb33f35532d35999389e 100644 (file)
@@ -222,8 +222,8 @@ static int run_ua_monitor_set_user_presence_condition(
 
        if (strlen(g_presence_and_cond))
                bitmask_and = (unsigned char)strtol(g_presence_and_cond, NULL, 10);
-       if (strlen(g_presence_and_cond))
-               bitmask_or = (unsigned char)strtol(g_absence_and_cond, NULL, 10);
+       if (strlen(g_presence_or_cond))
+               bitmask_or = (unsigned char)strtol(g_absence_or_cond, NULL, 10);
 
        msgb("AND [0x%u] OR [0x%u]", bitmask_and, bitmask_or);
 
index 0005510e1ae10ce864b82c6725912f466112222e..1859ec232a13c0d47a6ab813078e90bd0987f9a8 100644 (file)
@@ -72,36 +72,50 @@ static const char * __convert_device_mac_type_to_txt(ua_mac_type_e mac_type)
 static void __user_presence_detected_foreach_devices(gpointer data,
                                                     gpointer user_data)
 {
+       int ret;
        ua_device_h device_handle = (ua_device_h)data;
        char *account = (char *)user_data;
        ua_mac_type_e mac_type;
        char *mac = NULL;
 
-       ua_device_get_mac_address(device_handle, &mac);
-       ua_device_get_mac_type(device_handle, &mac_type);
+       ret = ua_device_get_mac_address(device_handle, &mac);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_device_get_mac_address() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
+       ret = ua_device_get_mac_type(device_handle, &mac_type);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_device_get_mac_type() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
        msgb("[%s] detected on [%s][%s]", account,
             __convert_device_mac_type_to_txt(mac_type), mac);
+
+       g_free(mac);
 }
 
 static void __user_presence_detected_cb(int result, ua_monitor_h monitor,
                ua_user_h user_handle, GSList *device_handles,
                void *user_data)
 {
+       int ret;
        char *account = NULL;
        char *pbuf = uat_get_time();
 
        msg("\n[%s]", pbuf);
        free(pbuf);
 
-       ua_user_get_account(user_handle, &account);
+       ret = ua_user_get_account(user_handle, &account);
+       if (UA_ERROR_NONE != ret) {
+               msg(" - ua_user_get_account() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+       }
        msgb("[%s] PRESENCE detected [%s]", account, uat_get_error_str(result));
        g_slist_foreach(device_handles,
                        __user_presence_detected_foreach_devices,
                        account);
 
-       if (account) {
-               free(account);
-       }
+       g_free(account);
 }
 
 static void __sensor_state_changed_cb(bool ready,