Fix possible issues for pkgmgr-info 52/202052/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 7 Dec 2018 10:27:15 +0000 (19:27 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 10 May 2019 05:35:31 +0000 (14:35 +0900)
- Change order of releasing resources according to SQLite recommendation.
- Change methods of lock from exclusive to deferred.
  This will allow processes to access db while modifying db
  except actual transaction.

Change-Id: I441d6c14b6b503f6f2b8599240efdfed36b6a617
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
(cherry picked from commit 87b8daea23c8d671f4284933cd71dfa9d349ea0a)
(cherry picked from commit 1ffc918a3b686f4f7c4fc55e816f0699a317728e)

parser/src/pkgmgr_parser_db.c
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_certinfo.c
src/pkgmgrinfo_db.c
src/pkgmgrinfo_pkginfo.c

index 6e50b39..448d2d1 100644 (file)
@@ -114,7 +114,7 @@ static const char *__get_bool(char *value, bool is_true)
 
 #define __BEGIN_TRANSACTION(db)                                                \
 do {                                                                           \
-       if (sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL) !=           \
+       if (sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL) !=            \
                        SQLITE_OK) {                                           \
                _LOGE("begin transaction failed: %s", sqlite3_errmsg(db));     \
                sqlite3_close_v2(db);                                          \
index 10d6d75..aee2c39 100644 (file)
@@ -712,8 +712,8 @@ catch:
                pkgmgrinfo_basic_free_application(info);
 
        g_list_free_full(bind_params, free);
-       sqlite3_close_v2(db);
        sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
 
        return ret;
 }
index f867c61..37d13de 100644 (file)
@@ -632,7 +632,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
        }
        free(dbpath);
 
-       ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       ret = sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("failed to begin transaction");
                sqlite3_close_v2(db);
@@ -743,7 +743,7 @@ API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
        }
        free(dbpath);
 
-       ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       ret = sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("failed to begin transaction");
                sqlite3_close_v2(db);
index e382bf5..af55535 100644 (file)
@@ -289,7 +289,7 @@ API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_
 
        /*Begin transaction*/
        /* Setting Manifest DB */
-       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN DEFERRED", NULL, NULL, NULL);
        tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Failed to begin transaction\n");
        _LOGD("Transaction Begin\n");
 
index d638493..aae7c0e 100644 (file)
@@ -604,9 +604,8 @@ catch:
                pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
 
        g_list_free_full(bind_params, free);
+       sqlite3_finalize(stmt);
        sqlite3_close_v2(db);
-       if (stmt)
-               sqlite3_finalize(stmt);
 
        return ret;
 }