Fixed svace issues.
authorsaerome.kim <saerome.kim@samsung.com>
Fri, 27 Sep 2019 01:38:01 +0000 (10:38 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 27 Sep 2019 05:42:07 +0000 (14:42 +0900)
410291: Potential Memory Leak.
410713: Handle leak of SQLLite statement.
401702, 410740, 410741: Memory leak.
410742: Missing null-check.

Change-Id: I709b77dc29699c434e94bc5645455bcfdeb53bed
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
packaging/ua-manager.spec
ua-daemon/src/pm/ua-light-plugin-handler.c
ua-daemon/src/pm/ua-motion-plugin-handler.c
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-db.c

index 10e1e2c..274dac7 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.10.1
+Version:    0.10.2
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index e96e38b..9f0d4e7 100644 (file)
@@ -62,6 +62,8 @@ void light_detection_callback(uas_detection_type_e type, void *sensor_info)
                _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_LIGHT, 0, light_info);
        }
 
+       g_free(light_info);
+
        FUNC_EXIT;
 }
 
index 39223dd..713a848 100644 (file)
@@ -63,6 +63,8 @@ void motion_detection_callback(uas_detection_type_e type, void *sensor_info)
                _uam_core_handle_absence_detected(UAM_SENSOR_BITMASK_MOTION, 0, motion_info);
        }
 
+       g_free(motion_info);
+
        FUNC_EXIT;
 }
 
index 45f42e3..15786b7 100644 (file)
@@ -2972,6 +2972,10 @@ int _uam_core_start_active_device_scan(char *sender, unsigned int sensors, int d
        }
 
        scanner = g_malloc0(sizeof(uam_scanner_info_t));
+       if (scanner) {
+               UAM_ERR("Failed to allocate memory");
+               return UAM_ERROR_OUT_OF_MEMORY;
+       }
        scanner->name = g_strdup(sender);
        scanner->sensors |= sensors;
        scanner->timer = g_timeout_add_seconds(detection_period,
index 52a7685..4bb9e6a 100644 (file)
@@ -165,6 +165,7 @@ static int __uam_db_get_version(unsigned int *ver)
                stmt = NULL;
                FINALIZE(select_version);
                UAM_ERR("Failed to prepare \"%s\" query", sql);
+               sqlite3_free(sql);
                return rc;
        }
 
@@ -187,6 +188,8 @@ static int __uam_db_get_version(unsigned int *ver)
 
        FINALIZE(select_version);
        sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       sqlite3_free(sql);
        FUNC_EXIT;
        return error_code;
 }
@@ -195,15 +198,20 @@ static int __uam_db_update_version(unsigned int version)
 {
        FUNC_ENTRY;
        char *sql = NULL;
+       int ret = UAM_ERROR_NONE;
 
        sql = sqlite3_mprintf("PRAGMA user_version = '%d';", version);
-       retv_if(UAM_ERROR_NONE != __uam_db_exec_sql(sql, NULL), UAM_ERROR_DB_FAILED);
-       sqlite3_free(sql);
 
-       UAM_DBG("Successfully updated database version to %d", version);
+       ret = __uam_db_exec_sql(sql, NULL);
+       if (UAM_ERROR_NONE != ret)
+               UAM_DBG("failed to updated database version to %d", version);
+       else
+               UAM_DBG("Successfully updated database version to %d", version);
+
+       sqlite3_free(sql);
 
        FUNC_EXIT;
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 static int __uam_db_upgrade(unsigned int version)
@@ -338,12 +346,16 @@ static int __uam_db_check_integrity(void)
 static int __uam_db_set_locking_mode(void)
 {
        char *sql = NULL;
+       int ret = UAM_ERROR_NONE;
 
        sql = sqlite3_mprintf("PRAGMA locking_mode = NORMAL");
-       retv_if(UAM_ERROR_NONE != __uam_db_exec_sql(sql, NULL), UAM_ERROR_DB_FAILED);
+       ret = __uam_db_exec_sql(sql, NULL);
+       if (UAM_ERROR_NONE != ret)
+               ret = UAM_ERROR_DB_FAILED;
+
        sqlite3_free(sql);
 
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 static int __uam_db_create_table(const char *table_name)