Fix possible issues for pkgmgr-info 45/194845/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 7 Dec 2018 10:27:15 +0000 (19:27 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 11 Dec 2018 02:07:29 +0000 (11:07 +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>
parser/src/pkgmgr_parser_db.c
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_certinfo.c
src/pkgmgrinfo_db.c
src/pkgmgrinfo_pkginfo.c

index 8745594..a7a1004 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 f05c371..d8dbeac 100644 (file)
@@ -718,8 +718,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 23aea4b..6f3de1f 100644 (file)
@@ -630,7 +630,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);
@@ -741,7 +741,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 17b0c43..dd957df 100644 (file)
@@ -265,7 +265,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;
 }