[0.1.21] Fix format specifiers
[platform/core/account/account-manager.git] / server / src / account-server-db.c
index 807837d..8ba8eec 100644 (file)
@@ -41,8 +41,6 @@
 #include "account_type.h"
 #include "account-server-db.h"
 
-//typedef sqlite3_stmt* account_stmt;
-
 #define EMAIL_SERVICE_CMDLINE "/usr/bin/email-service"
 
 #define EMAIL_APPID "email-setting-efl"
@@ -61,8 +59,7 @@ static sqlite3* g_hAccountDB = NULL;
 static sqlite3* g_hAccountDB2 = NULL;
 static sqlite3* g_hAccountGlobalDB = NULL;
 static sqlite3* g_hAccountGlobalDB2 = NULL;
-pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t account_global_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 //static char *_account_dup_text(const char *text_data);
 static int _account_insert_custom(account_s *account, int account_id);
@@ -92,9 +89,8 @@ int _account_get_current_appid_cb(const pkgmgrinfo_appinfo_h handle, void *user_
 
        pkgmgr_ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
 
-       if( pkgmgr_ret != PMINFO_R_OK ){
+       if (pkgmgr_ret != PMINFO_R_OK)
                ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appid(%d)", pkgmgr_ret);
-       }
 
        item = _account_dup_text(appid);
        *appid_list = g_slist_append(*appid_list, item);
@@ -122,8 +118,9 @@ static inline int __read_proc(const char *path, char *buf, int size)
                ACCOUNT_ERROR("fd read error(%d)\n", fd);
                close(fd);
                return -1;
-       } else
+       } else {
                buf[ret] = 0;
+       }
 
        close(fd);
 
@@ -145,19 +142,18 @@ char *_account_get_proc_cmdline_bypid(int pid)
        return strdup(buf);
 }
 
-
 /*
 static int _account_execute_query_from_global_db(const char *query)
 {
        int rc = -1;
        char* pszErrorMsg = NULL;
 
-       if(!query){
+       if (!query) {
                ACCOUNT_ERROR("NULL query\n");
                return _ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
        }
 
-       if(!g_hAccountGlobalDB){
+       if (!g_hAccountGlobalDB) {
                ACCOUNT_ERROR("Global DB is not opened\n");
                return _ACCOUNT_ERROR_DB_NOT_OPENED;
        }
@@ -171,6 +167,7 @@ static int _account_execute_query_from_global_db(const char *query)
        return rc;
 }
 */
+
 /*
 static int _account_begin_transaction_from_global_db(void)
 {
@@ -179,10 +176,10 @@ static int _account_begin_transaction_from_global_db(void)
 
        ret = _account_execute_query_from_global_db("BEGIN IMMEDIATE TRANSACTION");
 
-       if (ret == SQLITE_BUSY){
+       if (ret == SQLITE_BUSY) {
                ACCOUNT_ERROR(" sqlite3 busy = %d", ret);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
-       } else if(ret != SQLITE_OK) {
+       } else if (ret != SQLITE_OK) {
                ACCOUNT_ERROR("_account_svc_begin_transaction_in_global_db fail :: %d", ret);
                return _ACCOUNT_ERROR_DB_FAILED;
        }
@@ -205,12 +202,12 @@ static int _account_end_transaction_from_global_db(bool is_success)
                ACCOUNT_DEBUG("_account_end_transaction ROLLBACK");
        }
 
-       if(ret == SQLITE_PERM) {
+       if (ret == SQLITE_PERM) {
                ACCOUNT_ERROR("Account permission denied :: %d", ret);
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
-       if (ret == SQLITE_BUSY){
+       if (ret == SQLITE_BUSY) {
                ACCOUNT_DEBUG(" sqlite3 busy = %d", ret);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
@@ -227,65 +224,64 @@ static int _account_end_transaction_from_global_db(bool is_success)
 
 int _account_global_db_open(void)
 {
-       int  rc = 0;
+       int rc = 0;
        int ret = -1;
        char account_db_path[256] = {0, };
 
-       _INFO( "start _account_global_db_open()");
+       _INFO("start _account_global_db_open()");
 
        ACCOUNT_MEMSET(account_db_path, 0x00, sizeof(account_db_path));
        ACCOUNT_GET_GLOBAL_DB_PATH(account_db_path, sizeof(account_db_path));
 
-       if( g_hAccountGlobalDB ) {
-               _ERR( "Account database is using in another app. %x", g_hAccountDB );
+       if (g_hAccountGlobalDB) {
+               _ERR("Account database is using in another app");
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
        ret = _account_db_handle_close(g_hAccountGlobalDB2);
-       if( ret != _ACCOUNT_ERROR_NONE )
-               ACCOUNT_DEBUG( "db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
+       if (ret != _ACCOUNT_ERROR_NONE)
+               ACCOUNT_DEBUG("db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
 
-       ACCOUNT_DEBUG( "before db_util_open()");
-//     if(mode == ACCOUNT_DB_OPEN_READWRITE)
+       ACCOUNT_DEBUG("before _account_global_db_open()");
+//     if (mode == ACCOUNT_DB_OPEN_READWRITE)
 //             rc = db_util_open(account_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
-//     else if(mode == ACCOUNT_DB_OPEN_READONLY)
+//     else if (mode == ACCOUNT_DB_OPEN_READONLY)
        rc = db_util_open_with_options(account_db_path, &g_hAccountGlobalDB, SQLITE_OPEN_READONLY, NULL);
 //     else
 //             return _ACCOUNT_ERROR_DB_NOT_OPENED;
-       ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
+       ACCOUNT_DEBUG("after _account_global_db_open() sqlite_rc = %d", rc);
 
-       if( rc == SQLITE_PERM || _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ) {
-               ACCOUNT_ERROR( "Account permission denied");
+       if (rc == SQLITE_PERM || _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Account permission denied");
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
-       if( rc == SQLITE_BUSY ) {
-               ACCOUNT_ERROR( "busy handler fail.");
+       if (rc == SQLITE_BUSY) {
+               ACCOUNT_ERROR("busy handler fail.");
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
-       if( rc != SQLITE_OK ) {
-               ACCOUNT_ERROR( "The database isn't connected." );
+       if (rc != SQLITE_OK) {
+               ACCOUNT_ERROR("The database isn't connected.");
                return _ACCOUNT_ERROR_DB_NOT_OPENED;
        }
 
-       _INFO( "end _account_global_db_open()");
+       _INFO("end _account_global_db_open()");
        return _ACCOUNT_ERROR_NONE;
 }
 
 int _account_global_db_close(void)
 {
-       ACCOUNT_DEBUG( "start account_global_db_close()");
+       ACCOUNT_DEBUG("start account_global_db_close()");
        int ret = -1;
 /*
        ret = _account_db_handle_close(g_hAccountGlobalDB2);
-       if( ret != _ACCOUNT_ERROR_NONE )
-               ACCOUNT_DEBUG( "db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
+       if (ret != _ACCOUNT_ERROR_NONE)
+               ACCOUNT_DEBUG("db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
 */
        ret = _account_db_handle_close(g_hAccountGlobalDB);
-       if( ret != _ACCOUNT_ERROR_NONE )
-       {
-               ACCOUNT_ERROR( "db_util_close(g_hAccountGlobalDB) fail ret = %d", ret);
+       if (ret != _ACCOUNT_ERROR_NONE) {
+               ACCOUNT_ERROR("db_util_close(g_hAccountGlobalDB) fail ret = %d", ret);
                g_hAccountGlobalDB2 = g_hAccountGlobalDB;
        }
        g_hAccountGlobalDB = NULL;
@@ -296,7 +292,7 @@ int _account_global_db_close(void)
 static bool _account_check_add_more_account(const char* app_id)
 {
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
+       int                             rc = 0;
 
        ACCOUNT_RETURN_VAL((app_id != 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
@@ -307,7 +303,7 @@ static bool _account_check_add_more_account(const char* app_id)
        rc = _account_get_record_count(g_hAccountDB, query);
 
        /* multiple account support case (User DB & global DB) */
-       if(rc > 0 || _account_get_record_count(g_hAccountGlobalDB, query) > 0) {
+       if (rc > 0 || _account_get_record_count(g_hAccountGlobalDB, query) > 0) {
                ACCOUNT_SLOGD("app id (%s) supports multiple account. rc(%d)\n", app_id, rc);
                return TRUE;
        }
@@ -317,7 +313,7 @@ static bool _account_check_add_more_account(const char* app_id)
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE package_name = '%s'", ACCOUNT_TABLE, app_id);
        rc = _account_get_record_count(g_hAccountDB, query);
 
-       if(rc <= 0) {
+       if (rc <= 0) {
                ACCOUNT_SLOGD("app id (%s) supports single account. and there is no account of the app id\n", app_id);
                return TRUE;
        }
@@ -328,54 +324,53 @@ static bool _account_check_add_more_account(const char* app_id)
 
 int _account_db_open(int mode, int pid, uid_t uid)
 {
-       int  rc = 0;
+       int rc = 0;
        int ret = -1;
        char account_db_dir[256] = {0, };
        char account_db_path[256] = {0, };
 
-       _INFO( "start _account_db_open()");
+       _INFO("start _account_db_open() pid [%d]. uid [%d]", pid, uid);
 
        ACCOUNT_MEMSET(account_db_dir, 0x00, sizeof(account_db_dir));
        ACCOUNT_MEMSET(account_db_path, 0x00, sizeof(account_db_path));
 
        ACCOUNT_GET_USER_DB_PATH(account_db_path, sizeof(account_db_path), uid);
 
-       if( g_hAccountDB ) {
-               _ERR( "Account database is using in another app. %x", g_hAccountDB );
+       if (g_hAccountDB) {
+               _ERR("Account database is using in another app");
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
        ret = _account_db_handle_close(g_hAccountDB2);
-       if( ret != _ACCOUNT_ERROR_NONE )
-               ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
+       if (ret != _ACCOUNT_ERROR_NONE)
+               ACCOUNT_DEBUG("db_util_close(g_hAccountDB2) fail ret = %d", ret);
 
        ACCOUNT_GET_USER_DB_DIR(account_db_dir, sizeof(account_db_dir), uid);
 
-       if (mkdir(account_db_dir, 644) != 0)
-               ACCOUNT_DEBUG("mkdir \"%s\" fail", account_db_dir);
+       if (mkdir(account_db_dir, 0777) != 0)
+               ACCOUNT_DEBUG("\"%s\" is already exist directory", account_db_dir);
 
-
-       ACCOUNT_DEBUG( "before db_util_open()");
-//     if(mode == ACCOUNT_DB_OPEN_READWRITE)
+       ACCOUNT_DEBUG("before db_util_open()");
+//     if (mode == ACCOUNT_DB_OPEN_READWRITE)
                rc = db_util_open(account_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
-//     else if(mode == ACCOUNT_DB_OPEN_READONLY)
+//     else if (mode == ACCOUNT_DB_OPEN_READONLY)
 //             rc = db_util_open_with_options(account_db_path, &g_hAccountDB, SQLITE_OPEN_READONLY, NULL);
 //     else
 //             return _ACCOUNT_ERROR_DB_NOT_OPENED;
-       ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
+       ACCOUNT_DEBUG("after db_util_open() sqlite_rc = %d", rc);
 
-       if( rc == SQLITE_PERM || _account_db_err_code(g_hAccountDB) == SQLITE_PERM ) {
-               ACCOUNT_ERROR( "Account permission denied");
+       if (rc == SQLITE_PERM || _account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Account permission denied");
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
-       if( rc == SQLITE_BUSY ) {
-               ACCOUNT_ERROR( "busy handler fail.");
+       if (rc == SQLITE_BUSY) {
+               ACCOUNT_ERROR("busy handler fail.");
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
-       if( rc != SQLITE_OK ) {
-               ACCOUNT_ERROR( "The database isn't connected." );
+       if (rc != SQLITE_OK) {
+               ACCOUNT_ERROR("The database isn't connected.");
                return _ACCOUNT_ERROR_DB_NOT_OPENED;
        }
 
@@ -394,23 +389,22 @@ int _account_db_open(int mode, int pid, uid_t uid)
                }
        }
 
-       _INFO( "end _account_db_open()");
+       _INFO("end _account_db_open()");
        return _ACCOUNT_ERROR_NONE;
 }
 
 int _account_db_close(void)
 {
-       ACCOUNT_DEBUG( "start db_util_close()");
+       ACCOUNT_DEBUG("start db_util_close()");
        int ret = -1;
 /*
        ret = _account_db_handle_close(g_hAccountDB2);
-       if( ret != _ACCOUNT_ERROR_NONE )
-               ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
+       if (ret != _ACCOUNT_ERROR_NONE)
+               ACCOUNT_DEBUG("db_util_close(g_hAccountDB2) fail ret = %d", ret);
 */
        ret = _account_db_handle_close(g_hAccountDB);
-       if( ret != _ACCOUNT_ERROR_NONE )
-       {
-               ACCOUNT_ERROR( "db_util_close(g_hAccountDB) fail ret = %d", ret);
+       if (ret != _ACCOUNT_ERROR_NONE) {
+               ACCOUNT_ERROR("db_util_close(g_hAccountDB) fail ret = %d", ret);
                g_hAccountDB2 = g_hAccountDB;
        }
        g_hAccountDB = NULL;
@@ -425,7 +419,7 @@ static int _account_execute_insert_query(account_s *account)
        int                             rc = 0;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        /* check whether app id exist in account type db */
 
@@ -452,9 +446,9 @@ static int _account_execute_insert_query(account_s *account)
        rc = _account_query_step(hstmt);
        if (rc != SQLITE_DONE) {
                _INFO("");
-               ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
 
-               if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
+               if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM)
                        error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                else
                        error_code = _ACCOUNT_ERROR_DB_FAILED;
@@ -472,14 +466,14 @@ static int _account_execute_insert_query(account_s *account)
 static int _account_insert_capability(account_s *account, int account_id)
 {
        _INFO("_account_insert_capability start");
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account->capablity_list)==0) {
-               ACCOUNT_DEBUG( "_account_insert_capability, no capability\n");
+       if (g_slist_length(account->capablity_list) == 0) {
+               ACCOUNT_DEBUG("_account_insert_capability, no capability\n");
                return _ACCOUNT_ERROR_NONE;
        }
 
@@ -488,13 +482,13 @@ static int _account_insert_capability(account_s *account, int account_id)
        _INFO("_account_insert_capability _account_get_record_count [%s]", query);
        rc = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               _ERR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               _ERR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
-       if (rc <= 0) {
+
+       if (rc <= 0)
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
-       }
 
        /* insert query*/
 
@@ -531,7 +525,7 @@ static int _account_insert_capability(account_s *account, int account_id)
                _INFO("_account_insert_capability _account_query_step[%d]", rc);
 
                if (rc != SQLITE_DONE) {
-                       _ERR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+                       _ERR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
                        break;
                }
 
@@ -547,14 +541,14 @@ static int _account_insert_capability(account_s *account, int account_id)
 
 static int _account_update_capability(account_s *account, int account_id)
 {
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account->capablity_list)==0) {
-               ACCOUNT_ERROR( "_account_update_capability, no capability\n");
+       if (g_slist_length(account->capablity_list) == 0) {
+               ACCOUNT_ERROR("_account_update_capability, no capability\n");
                return _ACCOUNT_ERROR_NONE;
        }
 
@@ -563,7 +557,7 @@ static int _account_update_capability(account_s *account, int account_id)
        rc = _account_get_record_count(g_hAccountDB, query);
 
        if (rc <= 0) {
-               ACCOUNT_SLOGI( "_account_update_capability : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_SLOGI("_account_update_capability : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
        }
 
@@ -576,7 +570,9 @@ static int _account_update_capability(account_s *account, int account_id)
        rc = _account_query_step(hstmt);
 
        if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               if (_account_query_finalize(hstmt) != _ACCOUNT_ERROR_NONE)
+                       _ERR("finalize error - account_query_step() failed");
                return _ACCOUNT_ERROR_DB_FAILED;
        }
        rc = _account_query_finalize(hstmt);
@@ -613,7 +609,7 @@ static int _account_update_capability(account_s *account, int account_id)
                rc = _account_query_step(hstmt);
 
                if (rc != SQLITE_DONE) {
-                       ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+                       ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
                        break;
                }
 
@@ -626,16 +622,16 @@ static int _account_update_capability(account_s *account, int account_id)
        return _ACCOUNT_ERROR_NONE;
 }
 
-static int _account_update_capability_by_user_name(account_s *account, const char *user_name, const char *package_name )
+static int _account_update_capability_by_user_name(account_s *account, const char *user_name, const char *package_name)
 {
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account->capablity_list)==0) {
-               ACCOUNT_ERROR( "_account_update_capability_by_user_name, no capability\n");
+       if (g_slist_length(account->capablity_list) == 0) {
+               ACCOUNT_ERROR("_account_update_capability_by_user_name, no capability\n");
                return _ACCOUNT_ERROR_NONE;
        }
 
@@ -644,7 +640,7 @@ static int _account_update_capability_by_user_name(account_s *account, const cha
        rc = _account_get_record_count(g_hAccountDB, query);
 
        if (rc <= 0) {
-               ACCOUNT_SLOGI( "_account_update_capability_by_user_name : related account item is not existed rc=%d , %s ", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_SLOGI("_account_update_capability_by_user_name : related account item is not existed rc=%d , %s ", rc, _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
        }
 
@@ -657,7 +653,9 @@ static int _account_update_capability_by_user_name(account_s *account, const cha
        _account_query_bind_text(hstmt, count++, (char*)account->user_name);
        rc = _account_query_step(hstmt);
        if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               if (_account_query_finalize(hstmt) != _ACCOUNT_ERROR_NONE)
+                       _ERR("finalize error - account_query_step() failed");
                return _ACCOUNT_ERROR_DB_FAILED;
        }
 
@@ -695,7 +693,7 @@ static int _account_update_capability_by_user_name(account_s *account, const cha
                rc = _account_query_step(hstmt);
 
                if (rc != SQLITE_DONE) {
-                       ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+                       ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
                        break;
                }
 
@@ -748,138 +746,141 @@ bool _account_add_custom_to_account_cb(const char* key, const char* value, accou
        return TRUE;
 }
 
-
-static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
+static void _account_compare_new_and_old_account_properties(account_s** new_account, account_s* old_account)
 {
-       int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
-       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                             rc = 0;
-       account_s *old_account = NULL;
-
-       ACCOUNT_RETURN_VAL((new_account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
-       ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
-       ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
-       old_account = (account_s*)calloc(1, sizeof(account_s));
-       if(!old_account) {
-               ACCOUNT_FATAL("Memory alloc fail\n");
-               return _ACCOUNT_ERROR_OUT_OF_MEMORY;
-       }
-
-       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
-       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
-       hstmt = _account_prepare_query(g_hAccountDB, query);
-
-       rc = _account_query_step(hstmt);
-       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
-
-       while (rc == SQLITE_ROW) {
-               _account_convert_column_to_account(hstmt, old_account);
-               rc = _account_query_step(hstmt);
+       if ((*new_account) == NULL || old_account == NULL) {
+               _ERR("invalid input params");
+               return;
        }
 
-       rc = _account_query_finalize(hstmt);
-       ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-       hstmt = NULL;
-
-       // get capability
-       error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account);
-       ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
-
-       // get custom text
-       error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account);
-       ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
-
        // compare
-       new_account->id = old_account->id;
+       (*new_account)->id = old_account->id;
 
        //user name
-       if(!new_account->user_name) {
-               if(old_account->user_name)
-                       new_account->user_name = _account_dup_text(old_account->user_name);
+       if (!(*new_account)->user_name) {
+               if (old_account->user_name)
+                       (*new_account)->user_name = _account_dup_text(old_account->user_name);
        }
 
        // display name
-       if(!new_account->display_name) {
-               if(old_account->display_name)
-                       new_account->display_name = _account_dup_text(old_account->display_name);
+       if (!(*new_account)->display_name) {
+               if (old_account->display_name)
+                       (*new_account)->display_name = _account_dup_text(old_account->display_name);
        }
 
        // email address
-       if(!new_account->email_address) {
-               if(old_account->email_address)
-                       new_account->email_address = _account_dup_text(old_account->email_address);
+       if (!(*new_account)->email_address) {
+               if (old_account->email_address)
+                       (*new_account)->email_address = _account_dup_text(old_account->email_address);
        }
 
        // domain name
-       if(!new_account->domain_name) {
-               if(old_account->domain_name)
-                       new_account->domain_name = _account_dup_text(old_account->domain_name);
+       if (!(*new_account)->domain_name) {
+               if (old_account->domain_name)
+                       (*new_account)->domain_name = _account_dup_text(old_account->domain_name);
        }
 
        // icon path
-       if(!new_account->icon_path) {
-               if(old_account->icon_path)
-                       new_account->icon_path = _account_dup_text(old_account->icon_path);
+       if (!(*new_account)->icon_path) {
+               if (old_account->icon_path)
+                       (*new_account)->icon_path = _account_dup_text(old_account->icon_path);
        }
 
        // source
-       if(!new_account->source) {
-               if(old_account->source)
-                       new_account->source = _account_dup_text(old_account->source);
+       if (!(*new_account)->source) {
+               if (old_account->source)
+                       (*new_account)->source = _account_dup_text(old_account->source);
        }
 
-       _ACCOUNT_FREE(new_account->package_name);
-       new_account->package_name = _account_dup_text(old_account->package_name);
+       _ACCOUNT_FREE((*new_account)->package_name);
+       (*new_account)->package_name = _account_dup_text(old_account->package_name);
 
        // access token
-       if(!new_account->access_token) {
-               if(old_account->access_token)
-                       new_account->access_token = _account_dup_text(old_account->access_token);
+       if (!(*new_account)->access_token) {
+               if (old_account->access_token)
+                       (*new_account)->access_token = _account_dup_text(old_account->access_token);
        }
 
        // auth type
-       if(new_account->auth_type == _ACCOUNT_AUTH_TYPE_INVALID) {
-               new_account->auth_type = old_account->auth_type;
-       }
+       if ((*new_account)->auth_type == _ACCOUNT_AUTH_TYPE_INVALID)
+               (*new_account)->auth_type = old_account->auth_type;
 
        //secret
-       if(new_account->secret== _ACCOUNT_SECRECY_INVALID) {
-               new_account->secret = old_account->secret;
-       }
+       if ((*new_account)->secret == _ACCOUNT_SECRECY_INVALID)
+               (*new_account)->secret = old_account->secret;
 
        // sync support
-       if(new_account->sync_support == _ACCOUNT_SYNC_INVALID) {
-               new_account->sync_support = old_account->sync_support;
-       }
+       if ((*new_account)->sync_support == _ACCOUNT_SYNC_INVALID)
+               (*new_account)->sync_support = old_account->sync_support;
 
        // TODO user text
        int i;
-       for(i=0;i<USER_TXT_CNT;i++) {
-               if(!new_account->user_data_txt[i]) {
-                       if(old_account->user_data_txt[i])
-                               new_account->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
+       for (i = 0; i < USER_TXT_CNT; i++) {
+               if (!(*new_account)->user_data_txt[i]) {
+                       if (old_account->user_data_txt[i])
+                               (*new_account)->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
                }
        }
 
        // TODO user int
-       for(i=0;i<USER_INT_CNT;i++) {
-               if(new_account->user_data_int[i] == 0) {
-                               new_account->user_data_int[i] = old_account->user_data_int[i];
-               }
+       for (i = 0; i < USER_INT_CNT; i++) {
+               if ((*new_account)->user_data_int[i] == 0)
+                               (*new_account)->user_data_int[i] = old_account->user_data_int[i];
+       }
+
+       return;
+}
+
+
+static int _account_compare_old_record_by_user_name(account_s *new_account, const char* user_name, const char* package_name)
+{
+       int                             error_code = _ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                             rc = 0;
+       account_s *old_account = NULL;
+
+       ACCOUNT_RETURN_VAL((new_account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
+       ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
+       ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("PACKAGE NAME IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       old_account = (account_s*)calloc(1, sizeof(account_s));
+       if (!old_account) {
+               ACCOUNT_FATAL("Memory alloc fail\n");
+               return _ACCOUNT_ERROR_OUT_OF_MEMORY;
+       }
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = '%s' and package_name='%s'", ACCOUNT_TABLE, user_name, package_name);
+       hstmt = _account_prepare_query(g_hAccountDB, query);
+
+       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       while (rc == SQLITE_ROW) {
+               _account_convert_column_to_account(hstmt, old_account);
+               rc = _account_query_step(hstmt);
        }
 
-       // capability
+       rc = _account_query_finalize(hstmt);
+       ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+       hstmt = NULL;
+
+       // get capability
+       error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account, false);
+       ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
+
+       // get custom text
+       error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account, false);
+       ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
 
-       // user custom table
+       _account_compare_new_and_old_account_properties(&new_account, old_account);
 
 CATCH:
-       if (old_account) {
+       if (old_account)
                _account_free_account_with_items(old_account);
-       }
 
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
@@ -890,17 +891,15 @@ CATCH:
        return _ACCOUNT_ERROR_NONE;
 }
 
-
-
 static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *account, const char *user_name, const char *package_name)
 {
        int                             rc = 0, binding_count = 0, count = 0;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is NULL.\n"));
-       ACCOUNT_RETURN_VAL((package_name!= NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is NULL.\n"));
+       ACCOUNT_RETURN_VAL((package_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is NULL.\n"));
 
        char* current_appid = NULL;
        char* verified_appid = NULL;
@@ -911,22 +910,21 @@ static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *a
        _ACCOUNT_FREE(current_appid);
        _ACCOUNT_FREE(verified_appid);
 
-       if(error_code != _ACCOUNT_ERROR_NONE){
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("No permission to update\n");
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        error_code = encrypt_access_token(account);
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                _ERR("_encrypt_access_token error");
                return error_code;
        }
 
        _account_compare_old_record_by_user_name(account, user_name, package_name);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -945,8 +943,8 @@ static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *a
 
        count = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -965,9 +963,9 @@ static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *a
                        "int_custom0=?, int_custom1=?, int_custom2=?, int_custom3=?, int_custom4=? WHERE user_name=? and package_name=? ", ACCOUNT_TABLE);
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                _account_end_transaction(g_hAccountDB, FALSE);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
        ACCOUNT_RETURN_VAL((hstmt != NULL), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_svc_query_prepare() failed(%s).\n", _account_db_err_msg(g_hAccountDB)));
@@ -976,10 +974,11 @@ static int _account_update_account_by_user_name(int pid, uid_t uid, account_s *a
 
        _account_query_bind_text(hstmt, binding_count++, user_name);
        _account_query_bind_text(hstmt, binding_count++, package_name);
+
        rc = _account_query_step(hstmt);
-       if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
-       }
+       if (rc != SQLITE_DONE)
+               ACCOUNT_ERROR("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+
        rc = _account_query_finalize(hstmt);
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
        hstmt = NULL;
@@ -997,7 +996,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
 {
        _INFO("");
        int             error_code = _ACCOUNT_ERROR_NONE;
-       int     ret_transaction = 0;
+       int             ret_transaction = 0;
 
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
        ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
@@ -1016,9 +1015,9 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
        /* transaction control required*/
        ret_transaction = _account_begin_transaction(g_hAccountDB);
 
-       if(_account_db_err_code(g_hAccountDB) == SQLITE_PERM){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -1026,7 +1025,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
                ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
-       }else if (ret_transaction != _ACCOUNT_ERROR_NONE) {
+       } else if (ret_transaction != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&account_mutex);
                return ret_transaction;
@@ -1038,8 +1037,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
        char* appid = NULL;
        appid = _account_get_current_appid(pid, uid);
 
-       if(!appid)
-       {
+       if (!appid) {
                _INFO("");
                // API caller cannot be recognized
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
@@ -1052,8 +1050,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
        char* verified_appid = NULL;
        error_code  = _account_get_represented_appid_from_db(g_hAccountDB, g_hAccountGlobalDB, appid, uid, &verified_appid);//FIX
        _ACCOUNT_FREE(appid);
-       if(error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                _ERR("error_code = %d", error_code);
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("App id is not registered in account type DB, transaction ret (%x)!!!!\n", ret_transaction);
@@ -1062,8 +1059,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
                return error_code;
        }
 
-       if(verified_appid)
-       {
+       if (verified_appid) {
                _INFO("");
                error_code = _account_check_duplicated(g_hAccountDB, data, verified_appid, uid);
                if (error_code != _ACCOUNT_ERROR_NONE) {
@@ -1074,7 +1070,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
                        pthread_mutex_unlock(&account_mutex);
                        return error_code;
                }
-               if(!_account_check_add_more_account(verified_appid)) {
+               if (!_account_check_add_more_account(verified_appid)) {
                        ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                        ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
                        pthread_mutex_unlock(&account_mutex);
@@ -1087,8 +1083,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
                _ACCOUNT_FREE(verified_appid);
        }
 
-       if(!_account_check_add_more_account(data->package_name))
-       {
+       if (!_account_check_add_more_account(data->package_name)) {
                _INFO("");
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("No more account cannot be added, transaction ret (%x)!!!!\n", ret_transaction);
@@ -1097,8 +1092,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
        }
 
        error_code = encrypt_access_token(data);
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("encrypt_access_token fail, rollback insert query(%x)!!!!\n", ret_transaction);
                *account_id = -1;
@@ -1108,8 +1102,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
 
        error_code = _account_execute_insert_query(data);
 
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                _INFO("");
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("INSERT account fail, rollback insert query(%x)!!!!\n", ret_transaction);
@@ -1120,8 +1113,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
 
        _INFO("");
        error_code = _account_insert_capability(data, *account_id);
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                _INFO("");
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("INSERT capability fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
@@ -1132,8 +1124,7 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
 
        _INFO("");
        error_code = _account_insert_custom(data, *account_id);
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("INSERT custom fail, rollback insert capability query(%x)!!!!\n", ret_transaction);
                *account_id = -1;
@@ -1147,13 +1138,12 @@ int _account_insert_to_db(account_s* account, int pid, uid_t uid, int *account_i
        _account_end_transaction(g_hAccountDB, TRUE);
        ACCOUNT_SLOGD("(%s)-(%d) account _end_transaction.\n", __FUNCTION__, __LINE__);
 
-       char buf[64]={0,};
+       char buf[64] = {0,};
        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_INSERT, *account_id);
        _account_insert_delete_update_notification_send(buf);
        _INFO("account _notification_send end.");
 
        return _ACCOUNT_ERROR_NONE;
-
 }
 
 GSList* _account_get_capability_list_by_account_id(int account_id, int *error_code)
@@ -1161,19 +1151,19 @@ GSList* _account_get_capability_list_by_account_id(int account_id, int *error_co
        *error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
+       int                             rc = 0;
        GSList* capability_list = NULL;
 
-       ACCOUNT_RETURN_VAL((account_id > 0), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("ACCOUNT INDEX IS LESS THAN 0"));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((account_id > 0), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("ACCOUNT INDEX IS LESS THAN 0"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), { *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return NULL;
        }
@@ -1207,27 +1197,33 @@ GSList* _account_get_capability_list_by_account_id(int account_id, int *error_co
        }
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+       if (rc != _ACCOUNT_ERROR_NONE) {
+               _ERR("finalize error");
+               _account_gslist_capability_free(capability_list);
+               *error_code = rc;
+               return NULL;
+       }
+
        hstmt = NULL;
 
        *error_code = _ACCOUNT_ERROR_NONE;
 
 CATCH:
-       if (hstmt != NULL)
-       {
+       if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
                hstmt = NULL;
        }
 
        pthread_mutex_unlock(&account_mutex);
+
        return capability_list;
 }
 
 static int _account_compare_old_record(account_s *new_account, int account_id)
 {
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             rc = 0;
        account_s *old_account = NULL;
@@ -1260,106 +1256,24 @@ static int _account_compare_old_record(account_s *new_account, int account_id)
        hstmt = NULL;
 
        // get capability
-       error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account);
+       error_code = _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, old_account->id, (void*)old_account, false);
        ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("account_query_capability_by_account_id error"));
 
        // get custom text
-       error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account);
+       error_code = _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, old_account->id, (void*)old_account, false);
        ACCOUNT_CATCH_ERROR((error_code == _ACCOUNT_ERROR_NONE), {}, error_code, ("_account_query_custom_by_account_id error"));
 
-       // compare
-
-       new_account->id = old_account->id;
-
-       //user name
-       if(!new_account->user_name) {
-               if(old_account->user_name)
-                       new_account->user_name = _account_dup_text(old_account->user_name);
-       }
-
-       // display name
-       if(!new_account->display_name) {
-               if(old_account->display_name)
-                       new_account->display_name = _account_dup_text(old_account->display_name);
-       }
-
-       // email address
-       if(!new_account->email_address) {
-               if(old_account->email_address)
-                       new_account->email_address = _account_dup_text(old_account->email_address);
-       }
-
-       // domain name
-       if(!new_account->domain_name) {
-               if(old_account->domain_name)
-                       new_account->domain_name = _account_dup_text(old_account->domain_name);
-       }
-
-       // icon path
-       if(!new_account->icon_path) {
-               if(old_account->icon_path)
-                       new_account->icon_path = _account_dup_text(old_account->icon_path);
-       }
-
-       // source
-       if(!new_account->source) {
-               if(old_account->source)
-                       new_account->source = _account_dup_text(old_account->source);
-       }
-
-       _ACCOUNT_FREE(new_account->package_name);
-       new_account->package_name = _account_dup_text(old_account->package_name);
-
-       // access token
-       if(!new_account->access_token) {
-               if(old_account->access_token)
-                       new_account->access_token = _account_dup_text(old_account->access_token);
-       }
-
-       // user text
-       int i;
-       for(i=0;i<USER_TXT_CNT;i++) {
-               if(!new_account->user_data_txt[i]) {
-                       if(old_account->user_data_txt[i])
-                               new_account->user_data_txt[i] = _account_dup_text(old_account->user_data_txt[i]);
-               }
-       }
-
-       // auth type
-       if(new_account->auth_type == _ACCOUNT_AUTH_TYPE_INVALID) {
-               new_account->auth_type = old_account->auth_type;
-       }
-
-       //secret
-       if(new_account->secret== _ACCOUNT_SECRECY_INVALID) {
-               new_account->secret = old_account->secret;
-       }
-
-       // sync support
-       if(new_account->sync_support == _ACCOUNT_SYNC_INVALID) {
-               new_account->sync_support = old_account->sync_support;
-       }
-
-       // user int
-       for(i=0;i<USER_INT_CNT;i++) {
-               if(new_account->user_data_int[i] == 0) {
-                               new_account->user_data_int[i] = old_account->user_data_int[i];
-               }
-       }
-
-       // capability
-
-       // user custom table
+       _account_compare_new_and_old_account_properties(&new_account, old_account);
 
 CATCH:
-               if (old_account)
-                       _account_free_account_with_items(old_account);
+       if (old_account)
+               _account_free_account_with_items(old_account);
 
-               if (hstmt != NULL) {
-                       rc = _account_query_finalize(hstmt);
-                       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-                       hstmt = NULL;
-               }
+       if (hstmt != NULL) {
+               rc = _account_query_finalize(hstmt);
+               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+               hstmt = NULL;
+       }
 
        return _ACCOUNT_ERROR_NONE;
 }
@@ -1367,7 +1281,7 @@ CATCH:
 static int _account_get_package_name_from_account_id(int account_id, char **package_name)
 {
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             rc = 0;
        account_s *old_account = NULL;
@@ -1401,17 +1315,15 @@ static int _account_get_package_name_from_account_id(int account_id, char **pack
        // get package name.
        *package_name = _account_dup_text(old_account->package_name);
 
+CATCH:
+       if (old_account)
+               _account_free_account_with_items(old_account);
 
-       CATCH:
-               if (old_account) {
-                       _account_free_account_with_items(old_account);
-               }
-
-               if (hstmt != NULL) {
-                       rc = _account_query_finalize(hstmt);
-                       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-                       hstmt = NULL;
-               }
+       if (hstmt != NULL) {
+               rc = _account_query_finalize(hstmt);
+               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+               hstmt = NULL;
+       }
 
        return error_code;
 
@@ -1419,10 +1331,10 @@ static int _account_get_package_name_from_account_id(int account_id, char **pack
 
 static int _account_update_account(int pid, uid_t uid, account_s *account, int account_id)
 {
-       int                             rc = 0, binding_count =0;
+       int                             rc = 0, binding_count = 0;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                             error_code = _ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
-       account_stmt    hstmt = NULL;
+       int                             error_code = _ACCOUNT_ERROR_NONE, count = 0, ret_transaction = 0;
+       account_stmt    hstmt = NULL;
 
        if (!account->package_name) {
                ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
@@ -1436,7 +1348,7 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
        current_appid = _account_get_current_appid(pid, uid);
        error_code = _account_get_package_name_from_account_id(account_id, &package_name);
 
-       if(error_code != _ACCOUNT_ERROR_NONE || package_name == NULL){
+       if (error_code != _ACCOUNT_ERROR_NONE || package_name == NULL) {
                ACCOUNT_ERROR("No package name with account_id\n");
                _ACCOUNT_FREE(current_appid);
                _ACCOUNT_FREE(package_name);
@@ -1444,19 +1356,18 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
        }
 
        error_code = _account_check_appid_group_with_package_name(current_appid, package_name, uid);
-       ACCOUNT_DEBUG( "UPDATE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name);     // TODO: remove the log later.
+       ACCOUNT_DEBUG("UPDATE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name);      // TODO: remove the log later.
 
        _ACCOUNT_FREE(current_appid);
        _ACCOUNT_FREE(package_name);
 
-       if(error_code != _ACCOUNT_ERROR_NONE){
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("No permission to update\n");
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        error_code = encrypt_access_token(account);
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                _ERR("_encrypt_access_token error");
                return error_code;
        }
@@ -1467,11 +1378,11 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
                return error_code;
        }
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
-       } else if( _account_db_err_code(g_hAccountDB) == SQLITE_BUSY ){
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+       } else if (_account_db_err_code(g_hAccountDB) == SQLITE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
@@ -1492,8 +1403,8 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
 
        /* transaction control required*/
        ret_transaction = _account_begin_transaction(g_hAccountDB);
-       if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY ){
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+       if (ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
@@ -1506,9 +1417,9 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -1518,9 +1429,8 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
        _account_query_bind_int(hstmt, binding_count++, account_id);
 
        rc = _account_query_step(hstmt);
-       if (rc != SQLITE_DONE) {
-               ACCOUNT_SLOGE( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
-       }
+       if (rc != SQLITE_DONE)
+               ACCOUNT_SLOGE("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
 
        rc = _account_query_finalize(hstmt);
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
@@ -1530,7 +1440,7 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
 
        /*update capability*/
        error_code = _account_update_capability(account, account_id);
-       if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+       if (error_code != _ACCOUNT_ERROR_NONE && error_code != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
                return error_code;
@@ -1538,7 +1448,7 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
 
        /* update custom */
        error_code = _account_update_custom(account, account_id);
-       if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+       if (error_code != _ACCOUNT_ERROR_NONE && error_code != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
                return error_code;
@@ -1547,16 +1457,17 @@ static int _account_update_account(int pid, uid_t uid, account_s *account, int a
        ret_transaction = _account_end_transaction(g_hAccountDB, TRUE);
 
        _INFO("update end");
+
        return error_code;
 }
 
 
 static int _account_update_account_ex(account_s *account, int account_id)
 {
-       int                             rc = 0, binding_count =0;
+       int                             rc = 0, binding_count = 0;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                             error_code = _ACCOUNT_ERROR_NONE, count=0, ret_transaction = 0;
-       account_stmt    hstmt = NULL;
+       int                             error_code = _ACCOUNT_ERROR_NONE, count = 0, ret_transaction = 0;
+       account_stmt    hstmt = NULL;
 
        if (!account->package_name) {
                ACCOUNT_ERROR("Package name is mandetory field, it can not be NULL!!!!\n");
@@ -1564,8 +1475,7 @@ static int _account_update_account_ex(account_s *account, int account_id)
        }
 
        error_code = encrypt_access_token(account);
-       if (error_code != _ACCOUNT_ERROR_NONE)
-       {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                _ERR("_encrypt_access_token error");
                return error_code;
        }
@@ -1576,8 +1486,8 @@ static int _account_update_account_ex(account_s *account, int account_id)
                return error_code;
        }
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -1598,8 +1508,8 @@ static int _account_update_account_ex(account_s *account, int account_id)
 
        /* transaction control required*/
        ret_transaction = _account_begin_transaction(g_hAccountDB);
-       if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY ){
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+       if (ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
@@ -1612,9 +1522,9 @@ static int _account_update_account_ex(account_s *account, int account_id)
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -1628,9 +1538,8 @@ static int _account_update_account_ex(account_s *account, int account_id)
        _INFO("account_update_to_db_by_id_ex_p : after bind() : ret = %d", rc);
 
        rc = _account_query_step(hstmt);
-       if (rc != SQLITE_DONE) {
-               ACCOUNT_SLOGE( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
-       }
+       if (rc != SQLITE_DONE)
+               ACCOUNT_SLOGE("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
        _INFO("account_update_to_db_by_id_ex_p : after query_step() : ret = %d", rc);
 
        rc = _account_query_finalize(hstmt);
@@ -1641,7 +1550,7 @@ static int _account_update_account_ex(account_s *account, int account_id)
        _INFO("account_update_to_db_by_id_ex_p : before update_capability()");
        /*update capability*/
        error_code = _account_update_capability(account, account_id);
-       if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+       if (error_code != _ACCOUNT_ERROR_NONE && error_code != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
                return error_code;
@@ -1651,7 +1560,7 @@ static int _account_update_account_ex(account_s *account, int account_id)
        _INFO("account_update_to_db_by_id_ex_p : before update_custom()");
        /* update custom */
        error_code = _account_update_custom(account, account_id);
-       if(error_code != _ACCOUNT_ERROR_NONE && error_code!= _ACCOUNT_ERROR_RECORD_NOT_FOUND){
+       if (error_code != _ACCOUNT_ERROR_NONE && error_code != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
                ret_transaction = _account_end_transaction(g_hAccountDB, FALSE);
                ACCOUNT_ERROR("update capability Failed, trying to roll back(%x) !!!\n", ret_transaction);
                return error_code;
@@ -1676,14 +1585,14 @@ int _account_update_to_db_by_id(int pid, uid_t uid, account_s* account, int acco
 
        error_code = _account_update_account(pid, uid, data, account_id);
 
-       if(error_code != _ACCOUNT_ERROR_NONE) {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                pthread_mutex_unlock(&account_mutex);
                return error_code;
        }
 
        pthread_mutex_unlock(&account_mutex);
 
-       char buf[64]={0,};
+       char buf[64] = {0,};
        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_UPDATE, account_id);
        _account_insert_delete_update_notification_send(buf);
 
@@ -1704,21 +1613,20 @@ int _account_update_to_db_by_id_ex(account_s* account, int account_id)
        error_code = _account_update_account_ex(data, account_id);
        _INFO("after update_account_ex() : account_id[%d], user_name=%s", account_id, data->user_name);
 
-       if(error_code != _ACCOUNT_ERROR_NONE) {
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                pthread_mutex_unlock(&account_mutex);
                return error_code;
        }
 
        pthread_mutex_unlock(&account_mutex);
 
-       char buf[64]={0,};
+       char buf[64] = {0,};
        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_UPDATE, account_id);
        _account_insert_delete_update_notification_send(buf);
 
        return _ACCOUNT_ERROR_NONE;
 }
 
-
 int _account_update_to_db_by_user_name(int pid, uid_t uid, account_s* account, const char *user_name, const char *package_name)
 {
        ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("USER NAME IS NULL"));
@@ -1734,7 +1642,7 @@ int _account_update_to_db_by_user_name(int pid, uid_t uid, account_s* account, c
 
        pthread_mutex_unlock(&account_mutex);
 
-       char buf[64]={0,};
+       char buf[64] = {0,};
        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_UPDATE, data->id);
        _account_insert_delete_update_notification_send(buf);
 
@@ -1743,10 +1651,10 @@ int _account_update_to_db_by_user_name(int pid, uid_t uid, account_s* account, c
 
 GSList* _account_db_query_all(int pid, uid_t uid)
 {
-       //int                   error_code = _ACCOUNT_ERROR_NONE;
+       //int                   error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
+       int                             rc = 0;
        GSList                  *account_list = NULL;
 
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, NULL, ("The database isn't connected."));
@@ -1756,8 +1664,8 @@ GSList* _account_db_query_all(int pid, uid_t uid)
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TABLE);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return NULL;
        }
 
@@ -1765,13 +1673,12 @@ GSList* _account_db_query_all(int pid, uid_t uid)
 
        account_s *account_record = NULL;
 
-       if (rc != SQLITE_ROW)
-       {
+       if (rc != SQLITE_ROW) {
                _ERR("The record isn't found");
                goto CATCH;
        }
 
-       while(rc == SQLITE_ROW) {
+       while (rc == SQLITE_ROW) {
                account_record = (account_s*) malloc(sizeof(account_s));
 
                if (account_record == NULL) {
@@ -1786,7 +1693,7 @@ GSList* _account_db_query_all(int pid, uid_t uid)
        }
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, NULL, ("finalize error"));
+       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_gslist_account_free(account_list); }, NULL, ("finalize error"));
        hstmt = NULL;
 
        GSList* iter;
@@ -1794,34 +1701,34 @@ GSList* _account_db_query_all(int pid, uid_t uid)
        for (iter = account_list; iter != NULL; iter = g_slist_next(iter)) {
                account_s *account = NULL;
                account = (account_s*)iter->data;
-               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account->id, (void*)account);
-               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account->id, (void*)account);
+               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account->id, (void*)account, false);
+               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account->id, (void*)account, false);
        }
 
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_gslist_account_free(account_list);}, NULL, ("finalize error"));
+               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_gslist_account_free(account_list); }, NULL, ("finalize error"));
                hstmt = NULL;
        }
+
        if (account_list)
-       {
                _remove_sensitive_info_from_non_owning_account_slist(account_list, pid, uid);
-       }
+
        return account_list;
 }
 
 int _account_update_sync_status_by_id(uid_t uid, int account_db_id, const int sync_status)
 {
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             rc = 0;
-       int count =1;
+       int count = 1;
 
        ACCOUNT_RETURN_VAL((account_db_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-       if ( (sync_status < 0) || (sync_status >= _ACCOUNT_SYNC_MAX)) {
+       if ((sync_status < 0) || (sync_status >= _ACCOUNT_SYNC_MAX)) {
                ACCOUNT_SLOGE("(%s)-(%d) sync_status is less than 0 or more than enum max.\n", __FUNCTION__, __LINE__);
                return _ACCOUNT_ERROR_INVALID_PARAMETER;
        }
@@ -1834,14 +1741,14 @@ int _account_update_sync_status_by_id(uid_t uid, int account_db_id, const int sy
 
        rc = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        if (rc <= 0) {
-               ACCOUNT_SLOGE( "account_update_sync_status_by_id : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_SLOGE("account_update_sync_status_by_id : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
        }
@@ -1855,9 +1762,9 @@ int _account_update_sync_status_by_id(uid_t uid, int account_db_id, const int sy
 
        rc = _account_query_step(hstmt);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -1870,7 +1777,8 @@ int _account_update_sync_status_by_id(uid_t uid, int account_db_id, const int sy
                pthread_mutex_unlock(&account_mutex);
                return rc;
        }
-       char buf[64]={0,};
+
+       char buf[64] = {0,};
        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_SYNC_UPDATE, account_db_id);
        _account_insert_delete_update_notification_send(buf);
 
@@ -1886,39 +1794,48 @@ CATCH:
        }
 
        pthread_mutex_unlock(&account_mutex);
+
        return error_code;
 }
 
-int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record)
+int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record, bool query_del_acc)
 {
-       _INFO("_account_query_account_by_account_id() start, account_db_id=[%d]", account_db_id);
+       _INFO("_account_query_account_by_account_id() start, account_db_id=[%d], query_del_acc=[%d]", account_db_id, query_del_acc);
 
-       int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
-       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                             rc = 0;
+       int error_code = _ACCOUNT_ERROR_NONE;
+       account_stmt hstmt = NULL;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = 0;
 
        ACCOUNT_RETURN_VAL((account_db_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
        ACCOUNT_RETURN_VAL(account_record != NULL, {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
 
+       ACCOUNT_DEBUG("starting db operations");
+
+       /* prepare query for account-table */
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+       if (!query_del_acc)
+               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
+       else
+               ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", DELETED_ACCOUNT_TABLE, account_db_id);
 
-       ACCOUNT_DEBUG("starting db operations");
+       _INFO("after _account_prepare_query, rc=[%d]", rc);
 
-       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
        hstmt = _account_prepare_query(g_hAccountDB, query);
-       rc = _account_db_err_code(g_hAccountDB);
-       _INFO("after _account_prepare_query, rc=[%d]", rc);
 
-       if( rc == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       rc = _account_db_err_code(g_hAccountDB);
+       if (rc == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        ACCOUNT_DEBUG("before _account_query_step");
+
        rc = _account_query_step(hstmt);
+
        ACCOUNT_DEBUG("after _account_query_step returned [%d]", rc);
+
        ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        while (rc == SQLITE_ROW) {
@@ -1935,11 +1852,11 @@ int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id,
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
 
        ACCOUNT_DEBUG("before _account_query_capability_by_account_id");
-       _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account_record->id, (void*)account_record);
+       _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account_record->id, (void*)account_record, query_del_acc);
        ACCOUNT_DEBUG("after _account_query_capability_by_account_id");
 
        ACCOUNT_DEBUG("before _account_query_custom_by_account_id");
-       _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account_record->id, (void*)account_record);
+       _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account_record->id, (void*)account_record, query_del_acc);
        ACCOUNT_DEBUG("after _account_query_custom_by_account_id");
 
        hstmt = NULL;
@@ -1953,24 +1870,23 @@ CATCH:
        }
 
        if (account_record)
-       {
                _remove_sensitive_info_from_non_owning_account(account_record, pid, uid);
-       }
+
        pthread_mutex_unlock(&account_mutex);
        ACCOUNT_DEBUG("_account_query_account_by_account_id end [%d]", error_code);
+
        return error_code;
 }
 
 GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_name, int *error_code)
 {
        *error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             rc = 0;
        account_s *account_head = NULL;
 
-       if (user_name == NULL)
-       {
+       if (user_name == NULL) {
                _ERR("USER NAME IS NULL");
                *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
                goto CATCH;
@@ -1982,9 +1898,8 @@ GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM)
-       {
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                goto CATCH;
        }
@@ -1994,8 +1909,7 @@ GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_
 
        rc = _account_query_step(hstmt);
 
-       if (rc != SQLITE_ROW)
-       {
+       if (rc != SQLITE_ROW) {
                _ERR("The record isn't found");
                *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
@@ -2008,9 +1922,7 @@ GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_
                ACCOUNT_FATAL("malloc Failed");
                if (hstmt != NULL) {
                        rc = _account_query_finalize(hstmt);
-
-                       if (rc != _ACCOUNT_ERROR_NONE)
-                       {
+                       if (rc != _ACCOUNT_ERROR_NONE) {
                                _ERR("finalize error");
                                *error_code = rc;
                                goto CATCH;
@@ -2043,8 +1955,7 @@ GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_
 
        rc = _account_query_finalize(hstmt);
 
-       if (rc != _ACCOUNT_ERROR_NONE)
-       {
+       if (rc != _ACCOUNT_ERROR_NONE) {
                _ERR("finalize error");
                *error_code = rc;
                goto CATCH;
@@ -2054,18 +1965,16 @@ GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_
 
        GList *iter;
 
-
        tmp = g_list_length(account_head->account_list);
 
        for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
-//             account_h account;
-//             account = (account_h)iter->data;
+               //account_h account;
+               //account = (account_h)iter->data;
 
                account_s *testaccount = (account_s*)iter->data;
 
-               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount);
-               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount);
-
+               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount, false);
+               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount, false);
        }
 
        *error_code = _ACCOUNT_ERROR_NONE;
@@ -2073,8 +1982,7 @@ GList* _account_query_account_by_user_name(int pid, uid_t uid, const char *user_
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if (rc != _ACCOUNT_ERROR_NONE)
-               {
+               if (rc != _ACCOUNT_ERROR_NONE) {
                        _ERR("finalize error");
                        *error_code = rc;
                }
@@ -2082,13 +1990,14 @@ CATCH:
        }
 
        pthread_mutex_unlock(&account_mutex);
-       if (account_head)
-       {
+
+       if (account_head) {
                _remove_sensitive_info_from_non_owning_account_list(account_head->account_list, pid, uid);
                GList* result = account_head->account_list;
                _ACCOUNT_FREE(account_head);
                return result;
        }
+
        return NULL;
 }
 
@@ -2098,9 +2007,9 @@ _account_query_account_by_capability(int pid, uid_t uid, const char* capability_
        *error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
+       int                             rc = 0;
 
-       ACCOUNT_RETURN_VAL((capability_type != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("capability_type IS NULL"));
+       ACCOUNT_RETURN_VAL((capability_type != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("capability_type IS NULL"));
 
        if ((capability_value  < 0) || (capability_value >= _ACCOUNT_CAPABILITY_STATE_MAX)) {
                ACCOUNT_SLOGE("(%s)-(%d) capability_value is not equal to 0 or 1.\n", __FUNCTION__, __LINE__);
@@ -2108,7 +2017,7 @@ _account_query_account_by_capability(int pid, uid_t uid, const char* capability_
                return NULL;
        }
 
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), { *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
@@ -2116,8 +2025,8 @@ _account_query_account_by_capability(int pid, uid_t uid, const char* capability_
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return NULL;
        }
@@ -2139,7 +2048,7 @@ _account_query_account_by_capability(int pid, uid_t uid, const char* capability_
                ACCOUNT_FATAL("malloc Failed");
                if (hstmt != NULL) {
                        rc = _account_query_finalize(hstmt);
-                       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+                       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
                        hstmt = NULL;
                }
                *error_code = _ACCOUNT_ERROR_OUT_OF_MEMORY;
@@ -2176,29 +2085,28 @@ _account_query_account_by_capability(int pid, uid_t uid, const char* capability_
        tmp = g_list_length(account_head->account_list);
 
        for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
-//             account_h account = NULL;
-//             account = (account_h)iter->data;
+               //account_h account = NULL;
+               //account = (account_h)iter->data;
                account_s* testaccount = (account_s*)iter->data;
 
-               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount);
-               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount);
+               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount, false);
+               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount, false);
 
        }
 
-
        *error_code = _ACCOUNT_ERROR_NONE;
 
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if ( rc != _ACCOUNT_ERROR_NONE ) {
+               if (rc != _ACCOUNT_ERROR_NONE) {
                        *error_code = rc;
                        _ERR("finalize error");
                }
                hstmt = NULL;
        }
 
-       if( *error_code != _ACCOUNT_ERROR_NONE && account_head ) {
+       if (*error_code != _ACCOUNT_ERROR_NONE && account_head) {
                _account_glist_account_free(account_head->account_list);
                _ACCOUNT_FREE(account_head);
                account_head = NULL;
@@ -2206,13 +2114,13 @@ CATCH:
 
        pthread_mutex_unlock(&account_mutex);
 
-       if (account_head)
-       {
+       if (account_head) {
                _remove_sensitive_info_from_non_owning_account_list(account_head->account_list, pid, uid);
                GList* result = account_head->account_list;
                _ACCOUNT_FREE(account_head);
                return result;
        }
+
        return NULL;
 }
 
@@ -2221,10 +2129,10 @@ GList* _account_query_account_by_capability_type(int pid, uid_t uid, const char*
        *error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
+       int                             rc = 0;
 
-       ACCOUNT_RETURN_VAL((capability_type != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("capability_type IS NULL"));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;},
+       ACCOUNT_RETURN_VAL((capability_type != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("capability_type IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), { *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED; },
                                           NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
@@ -2233,8 +2141,8 @@ GList* _account_query_account_by_capability_type(int pid, uid_t uid, const char*
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return NULL;
        }
@@ -2255,7 +2163,7 @@ GList* _account_query_account_by_capability_type(int pid, uid_t uid, const char*
                ACCOUNT_FATAL("malloc Failed");
                if (hstmt != NULL) {
                        rc = _account_query_finalize(hstmt);
-                       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+                       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
                        hstmt = NULL;
                }
                *error_code = _ACCOUNT_ERROR_OUT_OF_MEMORY;
@@ -2294,16 +2202,15 @@ GList* _account_query_account_by_capability_type(int pid, uid_t uid, const char*
        for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
                account_s* testaccount = (account_s*)iter->data;
 
-               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount);
-               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount);
+               _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, testaccount->id, (void*)testaccount, false);
+               _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, testaccount->id, (void*)testaccount, false);
 
        }
 
        *error_code = _ACCOUNT_ERROR_NONE;
 
 CATCH:
-       if (hstmt != NULL)
-       {
+       if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
                if (rc != _ACCOUNT_ERROR_NONE) {
                        *error_code = rc;
@@ -2312,7 +2219,7 @@ CATCH:
                hstmt = NULL;
        }
 
-       if( (*error_code != _ACCOUNT_ERROR_NONE) && account_head ) {
+       if ((*error_code != _ACCOUNT_ERROR_NONE) && account_head) {
                _account_glist_account_free(account_head->account_list);
                _ACCOUNT_FREE(account_head);
                account_head = NULL;
@@ -2320,13 +2227,13 @@ CATCH:
 
        pthread_mutex_unlock(&account_mutex);
 
-       if (account_head)
-       {
+       if (account_head) {
                _remove_sensitive_info_from_non_owning_account_list(account_head->account_list, pid, uid);
                GList* result = account_head->account_list;
                _ACCOUNT_FREE(account_head);
                return result;
        }
+
        return NULL;
 }
 
@@ -2337,12 +2244,13 @@ GList* account_server_query_account_by_package_name(const char* package_name, in
        GList * account_list = NULL;
        *error_code = _ACCOUNT_ERROR_NONE;
 
-       ACCOUNT_RETURN_VAL((package_name != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("PACKAGE NAME IS NULL"));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((package_name != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("PACKAGE NAME IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), { *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
 
        account_list = _account_query_account_by_package_name(g_hAccountDB, package_name, error_code, pid, uid);
 
        _INFO("account_server_query_account_by_package_name end");
+
        return account_list;
 }
 
@@ -2358,13 +2266,14 @@ int account_server_delete_account_by_package_name(const char* package_name, bool
        error_code = _account_delete_account_by_package_name(g_hAccountDB, package_name, permission, pid, uid);
 
        _INFO("account_server_delete_account_by_package_name end");
+
        return error_code;
 }
 
 int _account_delete(int pid, uid_t uid, int account_id)
 {
-       int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       int error_code = _ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             rc = 0;
        int                             ret_transaction = 0;
@@ -2378,9 +2287,9 @@ int _account_delete(int pid, uid_t uid, int account_id)
 
        count = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2397,20 +2306,20 @@ int _account_delete(int pid, uid_t uid, int account_id)
 
        error_code = _account_get_package_name_from_account_id(account_id, &package_name);
 
-       if(error_code != _ACCOUNT_ERROR_NONE){
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("No package name with account_id\n");
                _ACCOUNT_FREE(current_appid);
                _ACCOUNT_FREE(package_name);
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
        }
-       ACCOUNT_DEBUG( "DELETE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name);
+       ACCOUNT_DEBUG("DELETE:account_id[%d],current_appid[%s]package_name[%s]", account_id, current_appid, package_name);
 
        error_code = _account_check_appid_group_with_package_name(current_appid, package_name, uid);
 
        _ACCOUNT_FREE(current_appid);
        _ACCOUNT_FREE(package_name);
 
-       if(error_code != _ACCOUNT_ERROR_NONE){
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("No permission to delete\n");
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
@@ -2418,14 +2327,14 @@ int _account_delete(int pid, uid_t uid, int account_id)
        /* transaction control required*/
        ret_transaction = _account_begin_transaction(g_hAccountDB);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
-       if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY ){
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+       if (ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
@@ -2436,14 +2345,15 @@ int _account_delete(int pid, uid_t uid, int account_id)
                return ret_transaction;
        }
 
+       /* capability table */
        ACCOUNT_MEMSET(query, 0x00, sizeof(query));
        ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2458,8 +2368,8 @@ int _account_delete(int pid, uid_t uid, int account_id)
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
        hstmt = NULL;
 
+       /* account table */
        ACCOUNT_MEMSET(query, 0, sizeof(query));
-
        ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
@@ -2475,7 +2385,6 @@ int _account_delete(int pid, uid_t uid, int account_id)
 
        /* delete custom data */
        ACCOUNT_MEMSET(query, 0, sizeof(query));
-
        ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
@@ -2495,7 +2404,7 @@ int _account_delete(int pid, uid_t uid, int account_id)
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if(rc != _ACCOUNT_ERROR_NONE ){
+               if (rc != _ACCOUNT_ERROR_NONE) {
                        ACCOUNT_ERROR("rc (%d)", rc);
                        is_success = FALSE;
                }
@@ -2509,7 +2418,7 @@ CATCH:
                ACCOUNT_ERROR("account_delete:_account_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
        } else {
                if (is_success == true) {
-                       char buf[64]={0,};
+                       char buf[64] = {0,};
                        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_DELETE, account_id);
                        _account_insert_delete_update_notification_send(buf);
                }
@@ -2518,7 +2427,6 @@ CATCH:
        pthread_mutex_unlock(&account_mutex);
 
        return error_code;
-
 }
 
 static int _account_query_account_by_username_and_package(const char* username, const char* package_name, account_s *account)
@@ -2526,7 +2434,7 @@ static int _account_query_account_by_username_and_package(const char* username,
        //FIXME
        //return -1;
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             rc = 0;
        int                             binding_count = 1;
@@ -2541,8 +2449,8 @@ static int _account_query_account_by_username_and_package(const char* username,
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE user_name = ? and package_name = ?", ACCOUNT_TABLE);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2561,8 +2469,8 @@ static int _account_query_account_by_username_and_package(const char* username,
 
        rc = _account_query_finalize(hstmt);
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-       _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account_record->id, (void*)account_record);
-       _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account_record->id, (void*)account_record);
+       _account_query_capability_by_account_id(g_hAccountDB, _account_add_capability_to_account_cb, account_record->id, (void*)account_record, false);
+       _account_query_custom_by_account_id(g_hAccountDB, _account_add_custom_to_account_cb, account_record->id, (void*)account_record, false);
 
        hstmt = NULL;
        error_code = _ACCOUNT_ERROR_NONE;
@@ -2575,6 +2483,7 @@ CATCH:
        }
 
        pthread_mutex_unlock(&account_mutex);
+
        return error_code;
 }
 
@@ -2594,10 +2503,10 @@ int _account_create(account_s **account)
        ACCOUNT_MEMSET(data, 0, sizeof(account_s));
 
        /*Setting account as visible by default*/
-//     data->secret = _ACCOUNT_SECRECY_VISIBLE;
+       //data->secret = _ACCOUNT_SECRECY_VISIBLE;
 
        /*Setting account as not supporting sync by default*/
-//     data->sync_support = _ACCOUNT_SYNC_NOT_SUPPORT;
+       //data->sync_support = _ACCOUNT_SYNC_NOT_SUPPORT;
 
        *account = data;
 
@@ -2617,12 +2526,11 @@ int _account_destroy(account_s *account)
 
 int _account_get_account_id(account_s* account, int *account_id)
 {
-       if (!account) {
+       if (!account)
                return _ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
-       if (!account_id) {
+
+       if (!account_id)
                return _ACCOUNT_ERROR_INVALID_PARAMETER;
-       }
 
        *account_id = account->id;
 
@@ -2633,14 +2541,14 @@ int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_na
 {
        _INFO("[%s][%s]", user_name, package_name);
 
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
-       int                     ret_transaction = 0;
+       int                             rc = 0;
+       int                             ret_transaction = 0;
        bool                    is_success = FALSE;
        account_s               *account = NULL;
-       int                     binding_count = 1;
+       int                             binding_count = 1;
        int                             account_id = -1;
 
        ACCOUNT_RETURN_VAL((user_name != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("user_name is null!"));
@@ -2655,14 +2563,14 @@ int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_na
 
        package_name_temp = _account_dup_text(package_name);
 
-       ACCOUNT_DEBUG( "DELETE:user_name[%s],current_appid[%s], package_name[%s]", user_name, current_appid, package_name_temp);
+       ACCOUNT_DEBUG("DELETE:user_name[%s],current_appid[%s], package_name[%s]", user_name, current_appid, package_name_temp);
 
        error_code = _account_check_appid_group_with_package_name(current_appid, package_name_temp, uid);
 
        _ACCOUNT_FREE(current_appid);
        _ACCOUNT_FREE(package_name_temp);
 
-       if(error_code != _ACCOUNT_ERROR_NONE){
+       if (error_code != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("No permission to delete\n");
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
@@ -2672,10 +2580,9 @@ int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_na
 
        _INFO("");
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
-       {
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                _account_destroy(account);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2689,21 +2596,18 @@ int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_na
        /* transaction control required*/
        ret_transaction = _account_begin_transaction(g_hAccountDB);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
-       {
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        _INFO("");
-       if( ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY )
-       {
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+       if (ret_transaction == _ACCOUNT_ERROR_DATABASE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
-       }
-       else if (ret_transaction != _ACCOUNT_ERROR_NONE) {
+       } else if (ret_transaction != _ACCOUNT_ERROR_NONE) {
                ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&account_mutex);
                return ret_transaction;
@@ -2715,10 +2619,10 @@ int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_na
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                _account_end_transaction(g_hAccountDB, FALSE);
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2789,7 +2693,7 @@ CATCH:
                ACCOUNT_ERROR("account_svc_delete:_account_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
        } else {
                if (is_success == true) {
-                       char buf[64]={0,};
+                       char buf[64] = {0,};
                        ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%d", _ACCOUNT_NOTI_NAME_DELETE, account_id);
                        _account_insert_delete_update_notification_send(buf);
                }
@@ -2808,7 +2712,7 @@ int _account_get_total_count_from_db(gboolean include_hidden, int *count)
                return _ACCOUNT_ERROR_INVALID_PARAMETER;
        }
 
-       if(!g_hAccountDB){
+       if (!g_hAccountDB) {
                ACCOUNT_ERROR("DB is not opened\n");
                return _ACCOUNT_ERROR_DB_NOT_OPENED;
        }
@@ -2817,19 +2721,15 @@ int _account_get_total_count_from_db(gboolean include_hidden, int *count)
        ACCOUNT_MEMSET(query, 0x00, sizeof(query));
 
        if (include_hidden)
-       {
                ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s", ACCOUNT_TABLE);
-       }
        else
-       {
                ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from %s where secret = %d", ACCOUNT_TABLE, _ACCOUNT_SECRECY_VISIBLE);
-       }
 
        *count = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&account_mutex);
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2874,6 +2774,7 @@ int account_server_query_app_id_exist(const char* app_id)
        ret = _account_type_query_app_id_exist_from_all_db(g_hAccountDB, g_hAccountGlobalDB, app_id);
 
        _INFO("account_server_query_app_id_exist end error_code=[%d]", ret);
+
        return ret;
 }
 
@@ -2894,6 +2795,7 @@ int account_server_insert_account_type_to_user_db(account_type_s *account_type,
 
        ret = _account_type_insert_to_db(g_hAccountDB, account_type, account_type_id);
        _INFO("account_server_insert_account_type_to_user_db end error_code=[%d]", ret);
+
        return ret;
 }
 
@@ -2906,6 +2808,7 @@ int account_server_delete_account_type_by_app_id_from_user_db(const char * app_i
 
        ret = _account_type_delete_by_app_id(g_hAccountDB, app_id);
        _INFO("account_server_delete_account_type_by_app_id_from_user_db end error_code=[%d]", ret);
+
        return ret;
 }
 
@@ -2917,9 +2820,9 @@ GSList* _account_type_query_provider_feature_by_app_id_from_global_db(const char
        int rc = 0, binding_count = 1;
        GSList* feature_list = NULL;
 
-       ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
-       ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL");}, NULL, (""));
-       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; _ERR("The database isn't connected.");}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((app_id != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL"); }, NULL, (""));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; _ERR("The database isn't connected."); }, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
@@ -2928,8 +2831,8 @@ GSList* _account_type_query_provider_feature_by_app_id_from_global_db(const char
 
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return NULL;
        }
@@ -2939,7 +2842,7 @@ GSList* _account_type_query_provider_feature_by_app_id_from_global_db(const char
 
        rc = _account_query_step(hstmt);
 
-       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from global db. rc=[%d]", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, { *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from global db. rc=[%d]", rc); }, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        provider_feature_s* feature_record = NULL;
 
@@ -2973,11 +2876,11 @@ CATCH:
                }
        }
 
-       if (*error_code != _ACCOUNT_ERROR_NONE) {
+       if (*error_code != _ACCOUNT_ERROR_NONE)
                _account_type_gslist_feature_free(feature_list);
-       }
 
        _INFO("Returning account feature_list from global db");
+
        return feature_list;
 }
 
@@ -2989,9 +2892,9 @@ GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *
        int rc = 0, binding_count = 1;
        GSList* feature_list = NULL;
 
-       ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
-       ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL");}, NULL, (""));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((app_id != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL"); }, NULL, (""));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), { *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
@@ -3000,8 +2903,8 @@ GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return NULL;
        }
@@ -3010,7 +2913,9 @@ GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *
 
        rc = _account_query_step(hstmt);
 
-       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from user db. rc=[%d]", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, { *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+                       _ERR("The record isn't found from user db. rc=[%d]", rc); },
+                               _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        provider_feature_s* feature_record = NULL;
 
@@ -3036,7 +2941,7 @@ GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *
        *error_code = _ACCOUNT_ERROR_NONE;
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_CATCH_ERROR_P((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, rc, ("account finalize error"));
+       ACCOUNT_CATCH_ERROR_P((rc == _ACCOUNT_ERROR_NONE), { *error_code = rc; }, rc, ("account finalize error"));
        hstmt = NULL;
 
 CATCH:
@@ -3050,23 +2955,25 @@ CATCH:
        }
        _INFO("*error_code=[%d]", *error_code);
 
-       if (*error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (*error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                feature_list = _account_type_query_provider_feature_by_app_id_from_global_db(app_id, error_code);
-       }
 
-       if (*error_code != _ACCOUNT_ERROR_NONE)
+       if (*error_code != _ACCOUNT_ERROR_NONE) {
                _account_type_gslist_feature_free(feature_list);
+               return NULL;
+       }
 
        _INFO("Returning account feature_list");
+
        return feature_list;
 }
 
-int _account_type_query_provider_feature_cb_by_app_id_from_global_db(account_type_provider_feature_cb callback, const char* app_id, void *user_data )
+int _account_type_query_provider_feature_cb_by_app_id_from_global_db(account_type_provider_feature_cb callback, const char* app_id, void *user_data)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
 
        _INFO("_account_type_query_provider_feature_cb_by_app_id_in_global_db start app_id=%s", app_id);
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
@@ -3078,15 +2985,15 @@ int _account_type_query_provider_feature_cb_by_app_id_from_global_db(account_typ
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_PERMISSION_DENIED, ("global db permission denied.\n"));
        }
 
        _account_query_bind_text(hstmt, binding_count++, app_id);
 
        rc = _account_query_step(hstmt);
-       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {_ERR("The record isn't found. rc=[%d]", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {_ERR("The record isn't found. rc=[%d]", rc); }, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        provider_feature_s* feature_record = NULL;
 
@@ -3125,15 +3032,16 @@ CATCH:
        }
 
        _INFO("_account_type_query_provider_feature_cb_by_app_id_in_global_db end. error_code=[%d]", error_code);
+
        return error_code;
 }
 
-int _account_type_query_provider_feature_cb_by_app_id(account_type_provider_feature_cb callback, const char* app_id, void *user_data )
+int _account_type_query_provider_feature_cb_by_app_id(account_type_provider_feature_cb callback, const char* app_id, void *user_data)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
 
        _INFO("_account_type_query_provider_feature_cb_by_app_id start app_id=%s", app_id);
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
@@ -3145,8 +3053,8 @@ int _account_type_query_provider_feature_cb_by_app_id(account_type_provider_feat
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -3192,17 +3100,17 @@ CATCH:
                hstmt = NULL;
        }
 /*
-       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
-       }
 */
        _INFO("_account_type_query_provider_feature_cb_by_app_id end");
+
        return error_code;
 }
 
-int account_type_query_provider_feature_cb_by_app_id(account_type_provider_feature_cb callback, const char* app_id, void *user_data )
+int account_type_query_provider_feature_cb_by_app_id(account_type_provider_feature_cb callback, const char* app_id, void *user_data)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
@@ -3210,9 +3118,8 @@ int account_type_query_provider_feature_cb_by_app_id(account_type_provider_featu
 
        error_code = _account_type_query_provider_feature_cb_by_app_id(callback, app_id, user_data);
 
-       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
-       }
 
        return error_code;
 }
@@ -3227,8 +3134,7 @@ bool _account_type_query_supported_feature_from_global_db(const char* app_id, co
        char query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int record_count = 0;
 
-       if (app_id == NULL || capability == NULL)
-       {
+       if (app_id == NULL || capability == NULL) {
                *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
                return false;
        }
@@ -3237,18 +3143,18 @@ bool _account_type_query_supported_feature_from_global_db(const char* app_id, co
 
        record_count = _account_get_record_count(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
-       if (record_count <= 0)
-       {
+       if (record_count <= 0) {
                *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
                return false;
        }
 
        _INFO("_account_type_query_supported_feature_in_global_db end");
+
        return true;
 }
 
@@ -3259,10 +3165,9 @@ bool _account_type_query_supported_feature(const char* app_id, const char* capab
        *error_code = _ACCOUNT_ERROR_NONE;
 
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     record_count = 0;
+       int                             record_count = 0;
 
-       if (app_id == NULL || capability == NULL)
-       {
+       if (app_id == NULL || capability == NULL) {
                *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
                return false;
        }
@@ -3271,14 +3176,13 @@ bool _account_type_query_supported_feature(const char* app_id, const char* capab
 
        record_count = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return false;
        }
 
-       if (record_count <= 0)
-       {
+       if (record_count <= 0) {
                bool is_exist = false;
                is_exist = _account_type_query_supported_feature_from_global_db(app_id, capability, error_code);
                if (!is_exist)
@@ -3286,32 +3190,33 @@ bool _account_type_query_supported_feature(const char* app_id, const char* capab
        }
 
        _INFO("_account_type_query_supported_feature end");
+
        return true;
 }
 
 
 static int _account_type_update_provider_feature(sqlite3 *account_db_handle, account_type_s *account_type, const char* app_id)
 {
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account_type != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account_type->provider_feature_list)==0) {
-               ACCOUNT_ERROR( "no feature\n");
+       if (g_slist_length(account_type->provider_feature_list) == 0) {
+               ACCOUNT_ERROR("no feature\n");
                return _ACCOUNT_ERROR_NONE;
        }
 
-       ACCOUNT_DEBUG( "app id", app_id);
+       ACCOUNT_DEBUG("app id[%s]", app_id);
 
        ACCOUNT_MEMSET(query, 0x00, sizeof(query));
 
        ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE app_id=? ", PROVIDER_FEATURE_TABLE);
        hstmt = _account_prepare_query(account_db_handle, query);
 
-       if( _account_db_err_code(account_db_handle) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(account_db_handle));
+       if (_account_db_err_code(account_db_handle) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(account_db_handle));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -3320,7 +3225,9 @@ static int _account_type_update_provider_feature(sqlite3 *account_db_handle, acc
        rc = _account_query_step(hstmt);
 
        if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+               ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+               if (_account_query_finalize(hstmt) != _ACCOUNT_ERROR_NONE)
+                       _ERR("finalize error - account_query_step() failed");
                return _ACCOUNT_ERROR_DB_FAILED;
        }
        rc = _account_query_finalize(hstmt);
@@ -3351,7 +3258,7 @@ static int _account_type_update_provider_feature(sqlite3 *account_db_handle, acc
                rc = _account_query_step(hstmt);
 
                if (rc != SQLITE_DONE) {
-                       ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+                       ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
                        break;
                }
                rc = _account_query_finalize(hstmt);
@@ -3364,23 +3271,22 @@ static int _account_type_update_provider_feature(sqlite3 *account_db_handle, acc
 
 static int _account_type_update_label(sqlite3 *account_db_handle, account_type_s *account_type, const char* app_id)
 {
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account_type != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account_type->label_list)==0) {
+       if (g_slist_length(account_type->label_list) == 0)
                return _ACCOUNT_ERROR_NONE;
-       }
 
        ACCOUNT_MEMSET(query, 0x00, sizeof(query));
 
        ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId=? ", LABEL_TABLE);
        hstmt = _account_prepare_query(account_db_handle, query);
 
-       if( _account_db_err_code(account_db_handle) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(account_db_handle));
+       if (_account_db_err_code(account_db_handle) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(account_db_handle));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -3389,7 +3295,9 @@ static int _account_type_update_label(sqlite3 *account_db_handle, account_type_s
        rc = _account_query_step(hstmt);
 
        if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+               ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+               if (_account_query_finalize(hstmt) != _ACCOUNT_ERROR_NONE)
+                       _ERR("finalize error - account_query_step() failed");
                return _ACCOUNT_ERROR_DB_FAILED;
        }
        rc = _account_query_finalize(hstmt);
@@ -3422,7 +3330,7 @@ static int _account_type_update_label(sqlite3 *account_db_handle, account_type_s
                rc = _account_query_step(hstmt);
 
                if (rc != SQLITE_DONE) {
-                       ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
+                       ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
                        break;
                }
                rc = _account_query_finalize(hstmt);
@@ -3436,10 +3344,10 @@ static int _account_type_update_label(sqlite3 *account_db_handle, account_type_s
 
 static int _account_type_update_account(sqlite3 *account_db_handle, account_type_s *account_type, const char* app_id)
 {
-       int                             rc = 0, binding_count =1;
+       int                             rc = 0, binding_count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                             error_code = _ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        if (!account_type->app_id) {
                ACCOUNT_ERROR("app id is mandetory field, it can not be NULL!!!!\n");
@@ -3452,11 +3360,11 @@ static int _account_type_update_account(sqlite3 *account_db_handle, account_type
 
        hstmt = _account_prepare_query(account_db_handle, query);
 
-       if( _account_db_err_code(account_db_handle) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(account_db_handle));
+       if (_account_db_err_code(account_db_handle) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(account_db_handle));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
-       } else if (_account_db_err_code(account_db_handle) == SQLITE_BUSY){
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(account_db_handle));
+       } else if (_account_db_err_code(account_db_handle) == SQLITE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(account_db_handle));
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
@@ -3466,9 +3374,8 @@ static int _account_type_update_account(sqlite3 *account_db_handle, account_type
        _account_query_bind_text(hstmt, binding_count++, app_id);
 
        rc = _account_query_step(hstmt);
-       if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
-       }
+       if (rc != SQLITE_DONE)
+               ACCOUNT_ERROR("account_db_query_step() failed(%d, %s)", rc, _account_db_err_msg(account_db_handle));
 
        rc = _account_query_finalize(hstmt);
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
@@ -3501,15 +3408,15 @@ int _account_type_update_to_db_by_app_id(account_type_s* account_type, const cha
        return error_code;
 }
 
-GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id, int *error_code )
+GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id, int *error_code)
 {
        *error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
        GSList* label_list = NULL;
 
-       ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((app_id != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
@@ -3517,8 +3424,8 @@ GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
 
                goto CATCH;
@@ -3527,7 +3434,7 @@ GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id
        _account_query_bind_text(hstmt, binding_count++, app_id);
 
        rc = _account_query_step(hstmt);
-       ACCOUNT_CATCH_ERROR_P((rc == SQLITE_ROW), {_ERR("The record isn't found. rc=[%d] done", rc);}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+       ACCOUNT_CATCH_ERROR_P((rc == SQLITE_ROW), {_ERR("The record isn't found. rc=[%d] done", rc); }, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        label_s* label_record = NULL;
 
@@ -3544,7 +3451,7 @@ GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id
                _account_type_convert_column_to_label(hstmt, label_record);
 
                _INFO("Adding account label_list");
-               label_list = g_slist_append (label_list, label_record);
+               label_list = g_slist_append(label_list, label_record);
 
                rc = _account_query_step(hstmt);
        }
@@ -3554,34 +3461,34 @@ GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if (rc != _ACCOUNT_ERROR_NONE) {
+               if (rc != _ACCOUNT_ERROR_NONE)
                        _ERR("global db finalize error[%d]", rc);
-               }
                hstmt = NULL;
        }
 
        _INFO("Returning account global label_list");
+
        return label_list;
 }
 
-GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_code )
+GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_code)
 {
        *error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
        GSList* label_list = NULL;
 
-       ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((app_id != NULL), { *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER; }, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), { *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                return NULL;
        }
@@ -3606,13 +3513,18 @@ GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_co
                _account_type_convert_column_to_label(hstmt, label_record);
 
                _INFO("Adding account label_list");
-               label_list = g_slist_append (label_list, label_record);
+               label_list = g_slist_append(label_list, label_record);
 
                rc = _account_query_step(hstmt);
        }
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+       if (rc != _ACCOUNT_ERROR_NONE) {
+                       _account_type_gslist_label_free(label_list);
+                       *error_code = rc;
+                       _ERR("finalize error");
+                       return NULL;
+               }
        hstmt = NULL;
 
        *error_code = _ACCOUNT_ERROR_NONE;
@@ -3620,24 +3532,29 @@ GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_co
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+               if (rc != _ACCOUNT_ERROR_NONE) {
+                       _account_type_gslist_label_free(label_list);
+                       *error_code = rc;
+                       _ERR("finalize error");
+                       return NULL;
+               }
                hstmt = NULL;
        }
 
-       if (*error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (*error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                label_list = _account_type_get_label_list_by_app_id_from_global_db(app_id, error_code);
-       }
 
        _INFO("Returning account label_list");
+
        return label_list;
 }
 
-int _account_type_query_label_by_app_id_from_global_db(account_type_label_cb callback, const char* app_id, void *user_data )
+int _account_type_query_label_by_app_id_from_global_db(account_type_label_cb callback, const char* app_id, void *user_data)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
 
        _INFO("account_type_query_label_by_app_id_from_global_db start");
 
@@ -3650,8 +3567,8 @@ int _account_type_query_label_by_app_id_from_global_db(account_type_label_cb cal
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                goto CATCH;
        }
@@ -3690,22 +3607,22 @@ int _account_type_query_label_by_app_id_from_global_db(account_type_label_cb cal
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if (rc != _ACCOUNT_ERROR_NONE) {
+               if (rc != _ACCOUNT_ERROR_NONE)
                        _ERR("global db finalize error[%d]", rc);
-               }
                hstmt = NULL;
        }
 
        _INFO("account_type_query_label_by_app_id_from_global_db end [%d]", error_code);
+
        return error_code;
 }
 
-int _account_type_query_label_by_app_id(account_type_label_cb callback, const char* app_id, void *user_data )
+int _account_type_query_label_by_app_id(account_type_label_cb callback, const char* app_id, void *user_data)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
@@ -3716,8 +3633,8 @@ int _account_type_query_label_by_app_id(account_type_label_cb callback, const ch
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -3745,8 +3662,8 @@ int _account_type_query_label_by_app_id(account_type_label_cb callback, const ch
 
                _account_type_free_label_with_items(label_record);
 
-//             ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
-               if(cb_ret == TRUE) {
+               //ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, _ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+               if (cb_ret != TRUE) {
                        _INFO("Callback func returs FALSE, its iteration is stopped!!!!\n");
                        break;
                }
@@ -3774,9 +3691,9 @@ CATCH:
        return error_code;
 }
 
-int account_type_query_label_by_app_id(account_type_label_cb callback, const char* app_id, void *user_data )
+int account_type_query_label_by_app_id(account_type_label_cb callback, const char* app_id, void *user_data)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int error_code = _ACCOUNT_ERROR_NONE;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((callback != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
@@ -3784,9 +3701,8 @@ int account_type_query_label_by_app_id(account_type_label_cb callback, const cha
 
        error_code = _account_type_query_label_by_app_id(callback, app_id, user_data);
 
-       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                error_code = _account_type_query_label_by_app_id_from_global_db(callback, app_id, user_data);
-       }
 
        return error_code;
 }
@@ -3836,10 +3752,10 @@ int _account_type_query_by_app_id_from_global_db(const char* app_id, account_typ
 {
        _INFO("_account_type_query_by_app_id_from_global_db start");
 
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
 
        ACCOUNT_RETURN_VAL((app_id != 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
@@ -3850,8 +3766,8 @@ int _account_type_query_by_app_id_from_global_db(const char* app_id, account_typ
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", ACCOUNT_TYPE_TABLE);
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -3868,9 +3784,9 @@ int _account_type_query_by_app_id_from_global_db(const char* app_id, account_typ
        }
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {_ERR("global db finalize error rc=[%d]", rc);}, rc, ("finalize error"));
+       ACCOUNT_CATCH_ERROR((rc == _ACCOUNT_ERROR_NONE), {_ERR("global db finalize error rc=[%d]", rc); }, rc, ("finalize error"));
        _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
-       _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
+       _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, app_id, (void*)(*account_type_record));
 
        hstmt = NULL;
        error_code = _ACCOUNT_ERROR_NONE;
@@ -3883,6 +3799,7 @@ CATCH:
        }
 
        _INFO("_account_type_query_by_app_id_from_global_db end [%d]", error_code);
+
        return error_code;
 }
 
@@ -3890,10 +3807,10 @@ int _account_type_query_by_app_id(const char* app_id, account_type_s** account_t
 {
        _INFO("_account_type_query_by_app_id start");
 
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
 
        ACCOUNT_RETURN_VAL((app_id != 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((account_type_record != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("account type record(account_type_s**) is NULL"));
@@ -3904,8 +3821,8 @@ int _account_type_query_by_app_id(const char* app_id, account_type_s** account_t
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", ACCOUNT_TYPE_TABLE);
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -3929,7 +3846,7 @@ int _account_type_query_by_app_id(const char* app_id, account_type_s** account_t
        rc = _account_query_finalize(hstmt);
        ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
        _account_type_query_label_by_app_id(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
-       _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
+       _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, app_id, (void*)(*account_type_record));
 
        hstmt = NULL;
        error_code = _ACCOUNT_ERROR_NONE;
@@ -3941,11 +3858,11 @@ CATCH:
                hstmt = NULL;
        }
 
-       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                error_code = _account_type_query_by_app_id_from_global_db(app_id, account_type_record);
-       }
 
        _INFO("_account_type_query_by_app_id end [%d]", error_code);
+
        return error_code;
 }
 
@@ -3954,19 +3871,17 @@ int _account_type_query_by_provider_feature_from_global_db(const char* key, GSLi
        int error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
+       int                             rc = 0;
        GSList                  *account_type_list = NULL;
 
        _INFO("_account_type_query_by_provider_feature_from_global_db start key=%s", key);
-       if(key == NULL)
-       {
+       if (key == NULL) {
                ACCOUNT_ERROR("capability_type IS NULL.");
                error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
                goto CATCH;
        }
 
-       if(g_hAccountGlobalDB == NULL)
-       {
+       if (g_hAccountGlobalDB == NULL) {
                ACCOUNT_ERROR("The database isn't connected.");
                error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;
                goto CATCH;
@@ -3978,9 +3893,8 @@ int _account_type_query_by_provider_feature_from_global_db(const char* key, GSLi
 
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM )
-       {
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                goto CATCH;
        }
@@ -3992,14 +3906,13 @@ int _account_type_query_by_provider_feature_from_global_db(const char* key, GSLi
 
        account_type_s *account_type_record = NULL;
 
-       if(rc != SQLITE_ROW)
-       {
+       if (rc != SQLITE_ROW) {
                ACCOUNT_ERROR("The record isn't found. rc=[%d]", rc);
                error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
        }
 
-       while(rc == SQLITE_ROW) {
+       while (rc == SQLITE_ROW) {
                account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
 
                if (account_type_record == NULL) {
@@ -4014,10 +3927,9 @@ int _account_type_query_by_provider_feature_from_global_db(const char* key, GSLi
        }
 
        rc = _account_query_finalize(hstmt);
-       if (rc != _ACCOUNT_ERROR_NONE )
-       {
+       if (rc != _ACCOUNT_ERROR_NONE) {
                _account_type_gslist_account_type_free(account_type_list);
-               ACCOUNT_ERROR("finalize error(%s)", rc);
+               ACCOUNT_ERROR("finalize error(%d)", rc);
                error_code = rc;
                goto CATCH;
        }
@@ -4028,8 +3940,8 @@ int _account_type_query_by_provider_feature_from_global_db(const char* key, GSLi
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
                account_type_s *account_type = NULL;
                account_type = (account_type_s*)iter->data;
-               _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
-               _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb, account_type->app_id, (void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, account_type->app_id, (void*)account_type);
                _INFO("add label & provider_feature");
        }
 
@@ -4047,15 +3959,15 @@ int _account_type_query_by_provider_feature_from_global_db(const char* key, GSLi
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if (rc != _ACCOUNT_ERROR_NONE)
-               {
-                       ACCOUNT_ERROR("finalize error(%s)", rc);
+               if (rc != _ACCOUNT_ERROR_NONE) {
+                       ACCOUNT_ERROR("finalize error(%d)", rc);
                        return rc;
                }
                hstmt = NULL;
        }
 
        _INFO("_account_type_query_by_provider_feature_from_global_db end. error_code=[%d]", error_code);
+
        return error_code;
 }
 
@@ -4068,15 +3980,13 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
        GSList *account_type_list = NULL;
 
        _INFO("account_type_query_by_provider_feature start key=%s", key);
-       if(key == NULL)
-       {
+       if (key == NULL) {
                ACCOUNT_ERROR("capability_type IS NULL.");
                *error_code = _ACCOUNT_ERROR_INVALID_PARAMETER;
                goto CATCH;
        }
 
-       if(g_hAccountDB == NULL)
-       {
+       if (g_hAccountDB == NULL) {
                ACCOUNT_ERROR("The database isn't connected.");
                *error_code = _ACCOUNT_ERROR_DB_NOT_OPENED;
                goto CATCH;
@@ -4088,9 +3998,8 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM )
-       {
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                *error_code = _ACCOUNT_ERROR_PERMISSION_DENIED;
                goto CATCH;
        }
@@ -4102,14 +4011,13 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
 
        account_type_s *account_type_record = NULL;
 
-       if(rc != SQLITE_ROW)
-       {
+       if (rc != SQLITE_ROW) {
                ACCOUNT_ERROR("The record isn't found. rc=[%d]", rc);
                *error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
        }
 
-       while(rc == SQLITE_ROW) {
+       while (rc == SQLITE_ROW) {
                account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
 
                if (account_type_record == NULL) {
@@ -4124,10 +4032,9 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
        }
 
        rc = _account_query_finalize(hstmt);
-       if (rc != _ACCOUNT_ERROR_NONE )
-       {
+       if (rc != _ACCOUNT_ERROR_NONE) {
                _account_type_gslist_account_type_free(account_type_list);
-               ACCOUNT_ERROR("finalize error(%s)", rc);
+               ACCOUNT_ERROR("finalize error(%d)", rc);
                *error_code = rc;
                goto CATCH;
        }
@@ -4138,8 +4045,8 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
                account_type_s *account_type = NULL;
                account_type = (account_type_s*)iter->data;
-               _account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
-               _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _account_type_query_label_by_app_id(_account_get_label_text_cb, account_type->app_id, (void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id, (void*)account_type);
        }
 
        *error_code = _ACCOUNT_ERROR_NONE;
@@ -4147,8 +4054,7 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               if (rc != _ACCOUNT_ERROR_NONE)
-               {
+               if (rc != _ACCOUNT_ERROR_NONE) {
                        *error_code = rc;
                        return NULL;
                }
@@ -4158,7 +4064,7 @@ CATCH:
        if (*error_code == _ACCOUNT_ERROR_NONE || *error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
                rc = _account_type_query_by_provider_feature_from_global_db(key, &account_type_list);
                if (rc != _ACCOUNT_ERROR_NONE && rc != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
-                       ACCOUNT_ERROR( "_account_type_query_by_provider_feature_from_global_db fail=[%d]", rc);
+                       ACCOUNT_ERROR("_account_type_query_by_provider_feature_from_global_db fail=[%d]", rc);
                        _account_type_gslist_account_type_free(account_type_list);
                        return NULL;
                }
@@ -4167,6 +4073,7 @@ CATCH:
        }
 
        _INFO("account_type_query_by_provider_feature end");
+
        return account_type_list;
 }
 
@@ -4188,21 +4095,20 @@ int _account_type_query_all_from_global_db(GSList **account_type_list_all)
 
        rc = _account_query_step(hstmt);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        account_type_s *account_type_record = NULL;
 
-       if (rc != SQLITE_ROW)
-       {
+       if (rc != SQLITE_ROW) {
                _INFO("[_ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
                error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
        }
 
-       while(rc == SQLITE_ROW) {
+       while (rc == SQLITE_ROW) {
                account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
 
                if (account_type_record == NULL) {
@@ -4217,7 +4123,7 @@ int _account_type_query_all_from_global_db(GSList **account_type_list_all)
        }
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list); }, rc, ("finalize error"));
        hstmt = NULL;
 
        GSList* iter;
@@ -4225,8 +4131,8 @@ int _account_type_query_all_from_global_db(GSList **account_type_list_all)
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
                account_type_s *account_type = NULL;
                account_type = (account_type_s*)iter->data;
-               _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
-               _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb, account_type->app_id, (void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, account_type->app_id, (void*)account_type);
        }
 
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
@@ -4237,15 +4143,16 @@ int _account_type_query_all_from_global_db(GSList **account_type_list_all)
        g_slist_free(account_type_list);
 
        error_code = _ACCOUNT_ERROR_NONE;
+
 CATCH:
-       if (hstmt != NULL)
-       {
+       if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, rc, ("finalize error"));
+               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list); }, rc, ("finalize error"));
                hstmt = NULL;
        }
 
        _INFO("_account_type_query_all_in_global_db end");
+
        return error_code;
 }
 
@@ -4267,21 +4174,20 @@ GSList* _account_type_query_all(void)
 
        rc = _account_query_step(hstmt);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return NULL;
        }
 
        account_type_s *account_type_record = NULL;
 
-       if (rc != SQLITE_ROW)
-       {
+       if (rc != SQLITE_ROW) {
                _INFO("[_ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
                error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
        }
 
-       while(rc == SQLITE_ROW) {
+       while (rc == SQLITE_ROW) {
                account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
 
                if (account_type_record == NULL) {
@@ -4296,7 +4202,7 @@ GSList* _account_type_query_all(void)
        }
 
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, NULL, ("finalize error"));
+       ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list); }, NULL, ("finalize error"));
        hstmt = NULL;
 
        GSList* iter;
@@ -4304,39 +4210,40 @@ GSList* _account_type_query_all(void)
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
                account_type_s *account_type = NULL;
                account_type = (account_type_s*)iter->data;
-               _account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
-               _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _account_type_query_label_by_app_id(_account_get_label_text_cb, account_type->app_id, (void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id, (void*)account_type);
        }
 
        error_code = _ACCOUNT_ERROR_NONE;
+
 CATCH:
-       if (hstmt != NULL)
-       {
+       if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, NULL, ("finalize error"));
+               ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list); }, NULL, ("finalize error"));
                hstmt = NULL;
        }
 
        if (error_code == _ACCOUNT_ERROR_NONE || error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
                error_code = _account_type_query_all_from_global_db(&account_type_list);
                if (rc != _ACCOUNT_ERROR_NONE && rc != _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
-                       ACCOUNT_ERROR( "_account_type_query_all_from_global_db fail=[%d]", rc);
+                       ACCOUNT_ERROR("_account_type_query_all_from_global_db fail=[%d]", rc);
                        _account_type_gslist_account_type_free(account_type_list);
                        return NULL;
                }
        }
 
        _INFO("_account_type_query_all end");
+
        return account_type_list;
 }
 
 // output parameter label must be free
 int _account_type_query_label_by_locale_from_global_db(const char* app_id, const char* locale, char **label)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
        char*                   converted_locale = NULL;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
@@ -4350,10 +4257,10 @@ int _account_type_query_label_by_locale_from_global_db(const char* app_id, const
        converted_locale = _account_dup_text(locale);
        gchar** tokens = g_strsplit(converted_locale, "-", 2);
 
-       if(tokens != NULL) {
-               if((char*)(tokens[1]) != NULL) {
+       if (tokens != NULL) {
+               if ((char*)(tokens[1]) != NULL) {
                        char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
-                       if(upper_token != NULL) {
+                       if (upper_token != NULL) {
                                _ACCOUNT_FREE(converted_locale);
                                converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
                        }
@@ -4367,8 +4274,8 @@ int _account_type_query_label_by_locale_from_global_db(const char* app_id, const
 
        hstmt = _account_prepare_query(g_hAccountGlobalDB, query);
 
-       if( _account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
+       if (_account_db_err_code(g_hAccountGlobalDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountGlobalDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -4389,7 +4296,7 @@ int _account_type_query_label_by_locale_from_global_db(const char* app_id, const
 
                ACCOUNT_MEMSET(label_record, 0x00, sizeof(label_s));
 
-               _account_type_convert_column_to_label(hstmt,label_record);
+               _account_type_convert_column_to_label(hstmt, label_record);
 
                _ACCOUNT_FREE(*label);
                //Making label newly created
@@ -4414,16 +4321,17 @@ CATCH:
        }
 
        _INFO("_account_type_query_label_by_locale_from_global_db() end : error_code = %d", error_code);
+
        return error_code;
 }
 
 // output parameter label must be free
 int _account_type_query_label_by_locale(const char* app_id, const char* locale, char **label)
 {
-       int                     error_code = _ACCOUNT_ERROR_NONE;
+       int                             error_code = _ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+       int                             rc = 0, binding_count = 1;
        char*                   converted_locale = NULL;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
@@ -4437,10 +4345,10 @@ int _account_type_query_label_by_locale(const char* app_id, const char* locale,
        converted_locale = _account_dup_text(locale);
        gchar** tokens = g_strsplit(converted_locale, "-", 2);
 
-       if(tokens != NULL) {
-               if((char*)(tokens[1]) != NULL) {
+       if (tokens != NULL) {
+               if ((char*)(tokens[1]) != NULL) {
                        char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
-                       if(upper_token != NULL) {
+                       if (upper_token != NULL) {
                                _ACCOUNT_FREE(converted_locale);
                                converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
                        }
@@ -4454,8 +4362,8 @@ int _account_type_query_label_by_locale(const char* app_id, const char* locale,
 
        hstmt = _account_prepare_query(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
@@ -4476,7 +4384,7 @@ int _account_type_query_label_by_locale(const char* app_id, const char* locale,
 
                ACCOUNT_MEMSET(label_record, 0x00, sizeof(label_s));
 
-               _account_type_convert_column_to_label(hstmt,label_record);
+               _account_type_convert_column_to_label(hstmt, label_record);
 
                _ACCOUNT_FREE(*label);
                //Making label newly created
@@ -4493,18 +4401,18 @@ int _account_type_query_label_by_locale(const char* app_id, const char* locale,
 
        error_code = _ACCOUNT_ERROR_NONE;
 
-       CATCH:
+CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
                ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
                hstmt = NULL;
        }
 
-       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+       if (error_code == _ACCOUNT_ERROR_RECORD_NOT_FOUND)
                error_code = _account_type_query_label_by_locale_from_global_db(app_id, locale, label);
-       }
 
        _INFO("_account_type_query_label_by_locale() end : error_code = %d", error_code);
+
        return error_code;
 }
 
@@ -4512,14 +4420,14 @@ static int _account_insert_custom(account_s *account, int account_id)
 {
        _INFO("_account_insert_custom start");
 
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account->custom_list)==0) {
-               ACCOUNT_DEBUG( "_account_insert_custom, no custom data\n");
+       if (g_slist_length(account->custom_list) == 0) {
+               ACCOUNT_DEBUG("_account_insert_custom, no custom data\n");
                return _ACCOUNT_ERROR_NONE;
        }
 
@@ -4527,13 +4435,13 @@ static int _account_insert_custom(account_s *account, int account_id)
 
        rc = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%d, %s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
        }
 
        if (rc <= 0) {
-               ACCOUNT_SLOGE( "_account_insert_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_SLOGE("_account_insert_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
        }
 
@@ -4550,8 +4458,8 @@ static int _account_insert_custom(account_s *account, int account_id)
 
                hstmt = _account_prepare_query(g_hAccountDB, query);
 
-               if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-                       ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+                       ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                        return _ACCOUNT_ERROR_PERMISSION_DENIED;
                }
 
@@ -4572,7 +4480,7 @@ static int _account_insert_custom(account_s *account, int account_id)
                rc = _account_query_step(hstmt);
 
                if (rc != SQLITE_DONE) {
-                       ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+                       ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
                        break;
                }
 
@@ -4583,19 +4491,20 @@ static int _account_insert_custom(account_s *account, int account_id)
        }
 
        _INFO("_account_insert_custom end");
+
        return _ACCOUNT_ERROR_NONE;
 }
 
 static int _account_update_custom(account_s *account, int account_id)
 {
-       int                     rc, count = 1;
+       int                             rc, count = 1;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       account_stmt    hstmt = NULL;
+       account_stmt    hstmt = NULL;
 
        ACCOUNT_RETURN_VAL((account != NULL), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
 
-       if (g_slist_length( account->custom_list)==0) {
-               ACCOUNT_DEBUG( "_account_update_custom, no custom data\n");
+       if (g_slist_length(account->custom_list) == 0) {
+               ACCOUNT_DEBUG("_account_update_custom, no custom data\n");
                return _ACCOUNT_ERROR_NONE;
        }
 
@@ -4603,18 +4512,18 @@ static int _account_update_custom(account_s *account, int account_id)
 
        rc = _account_get_record_count(g_hAccountDB, query);
 
-       if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+       if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+               ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_PERMISSION_DENIED;
-       } else if( _account_db_err_code(g_hAccountDB) == SQLITE_BUSY ){
-               ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg(g_hAccountDB));
+       } else if (_account_db_err_code(g_hAccountDB) == SQLITE_BUSY) {
+               ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
                pthread_mutex_unlock(&account_mutex);
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
        if (rc <= 0) {
-               ACCOUNT_SLOGE( "_account_update_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_SLOGE("_account_update_custom : related account item is not existed rc=%d , %s", rc, _account_db_err_msg(g_hAccountDB));
                return _ACCOUNT_ERROR_RECORD_NOT_FOUND;
        }
 
@@ -4627,10 +4536,14 @@ static int _account_update_custom(account_s *account, int account_id)
        rc = _account_query_step(hstmt);
 
        if (rc == SQLITE_BUSY) {
-               ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               if (_account_query_finalize(hstmt) != _ACCOUNT_ERROR_NONE)
+                       _ERR("finalize error - account_query_step() failed");
                return _ACCOUNT_ERROR_DATABASE_BUSY;
        } else if (rc != SQLITE_DONE) {
-               ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+               if (_account_query_finalize(hstmt) != _ACCOUNT_ERROR_NONE)
+                       _ERR("finalize error - account_query_step() failed");
                return _ACCOUNT_ERROR_DB_FAILED;
        }
 
@@ -4649,8 +4562,8 @@ static int _account_update_custom(account_s *account, int account_id)
 
                hstmt = _account_prepare_query(g_hAccountDB, query);
 
-               if( _account_db_err_code(g_hAccountDB) == SQLITE_PERM ){
-                       ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+               if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+                       ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
                        return _ACCOUNT_ERROR_PERMISSION_DENIED;
                }
 
@@ -4671,7 +4584,7 @@ static int _account_update_custom(account_s *account, int account_id)
                rc = _account_query_step(hstmt);
 
                if (rc != SQLITE_DONE) {
-                       ACCOUNT_ERROR( "_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
+                       ACCOUNT_ERROR("_account_query_step() failed(%d, %s)", rc, _account_db_err_msg(g_hAccountDB));
                        break;
                }