Fixed svace issues. accepted/tizen/unified/20190923.225303 submit/tizen/20190923.121724
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 23 Sep 2019 12:12:07 +0000 (21:12 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 23 Sep 2019 12:16:25 +0000 (21:16 +0900)
410290, 410291, 410292, 410293: Memory leak due to unrelaseing
returned pointer after calling sql3_mrprintf()

Change-Id: I4eb8c49027f25c1e901905848ee0ff6f930b440c
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
packaging/ua-manager.spec
ua-daemon/src/ua-manager-db.c

index aaf1bc4..c73b42e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.9.4
+Version:    0.9.5
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 7f6d568..04e66b4 100644 (file)
@@ -221,14 +221,20 @@ static int __uam_db_upgrade(unsigned int version)
 static int __uam_db_upgrade_version(unsigned int old_ver, unsigned int new_ver)
 {
        FUNC_ENTRY;
+       int ret = UAM_ERROR_NONE;
        unsigned int i;
 
        for (i = old_ver + 1; i <= new_ver; i++) {
-               retv_if(UAM_ERROR_NONE != __uam_db_upgrade(i), UAM_ERROR_DB_FAILED);
+               ret = __uam_db_upgrade(i);
+               if (UAM_ERROR_NONE != ret) {
+                       UAM_ERR("Faild to __uam_db_upgrade(%d)", i);
+                       ret = UAM_ERROR_DB_FAILED;
+                       break;
+               }
        }
 
        FUNC_EXIT;
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 int _uam_db_check_version(void)
@@ -309,16 +315,21 @@ static int __uam_db_check_integrity_cb(
 static int __uam_db_check_integrity(void)
 {
        FUNC_ENTRY;
+       int ret = UAM_ERROR_NONE;
        char *sql = NULL;
 
        sql = sqlite3_mprintf("PRAGMA integrity_check");
-       retv_if(UAM_ERROR_NONE != __uam_db_exec_sql(sql, __uam_db_check_integrity_cb), UAM_ERROR_DB_FAILED);
-       sqlite3_free(sql);
 
-       UAM_DBG("Successfully verified database integrity");
+       ret = __uam_db_exec_sql(sql, __uam_db_check_integrity_cb);
+       if (UAM_ERROR_NONE != ret)
+               UAM_ERR("Faild to __uam_db_exec_sql()");
+       else
+               UAM_DBG("Successfully verified database integrity");
+
+       sqlite3_free(sql);
 
        FUNC_EXIT;
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 static int __uam_db_set_locking_mode(void)
@@ -338,7 +349,13 @@ static int __uam_db_create_table(const char *table_name)
        int ret = UAM_ERROR_NONE;
 
        sql = sqlite3_mprintf(table_name);
-       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)
+               UAM_ERR("Faild to __uam_db_exec_sql()");
+       else
+               UAM_DBG("Successfully verified database integrity");
+
        sqlite3_free(sql);
 
        return ret;
@@ -392,7 +409,7 @@ int _uam_db_initialize_once(void)
 {
        FUNC_ENTRY;
        char *sql;
-
+       int ret= UAM_ERROR_NONE;
        int max_retries = 2;
        int max_attempts = 10;
 
@@ -413,8 +430,12 @@ int _uam_db_initialize_once(void)
 
        /* Enable persist journal mode */
        sql = sqlite3_mprintf("PRAGMA journal_mode = PERSIST");
-       retv_if(UAM_ERROR_NONE != __uam_db_exec_sql(sql, NULL), UAM_ERROR_DB_FAILED);
+       ret = __uam_db_exec_sql(sql, NULL);
        sqlite3_free(sql);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_ERR("Faile to __uam_db_exec_sql()");
+               return UAM_ERROR_DB_FAILED;
+       }
 
        if (NULL == database) {
                unlink(DATABASE_FULL_PATH);
@@ -422,11 +443,13 @@ int _uam_db_initialize_once(void)
        }
 
        /* Set how many times we'll repeat our attempts for sqlite_step */
-       if (SQLITE_OK != sqlite3_busy_handler(database, __uam_db_busy, &max_attempts))
+       if (SQLITE_OK != sqlite3_busy_handler(database, __uam_db_busy, &max_attempts)) {
                UAM_ERR("Couldn't set busy handler!");
+               return UAM_ERROR_DB_FAILED;
+       }
 
        FUNC_EXIT;
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 sqlite3 *__uam_db_recover_database(void)