Set default value for launch_mode
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_certinfo.c
index 0bcf967..c626b51 100644 (file)
@@ -116,7 +116,7 @@ API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id,
 {
        int ret;
        sqlite3 *db;
-       const char *dbpath;
+       char *dbpath;
 
        if (lhs_package_id == NULL || rhs_package_id == NULL ||
                        compare_result == NULL) {
@@ -129,11 +129,13 @@ API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id,
        if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
        if (ret != SQLITE_OK) {
                _LOGE("failed to open db: %d", ret);
+               free(dbpath);
                return PMINFO_R_ERROR;
        }
+       free(dbpath);
 
        if (_pkginfo_compare_certinfo(db, lhs_package_id, rhs_package_id,
                                compare_result)) {
@@ -159,18 +161,20 @@ static int _pkginfo_get_pkgid_from_appid(uid_t uid, const char *appid,
                "SELECT package FROM package_app_info WHERE app_id=?";
        int ret;
        sqlite3 *db;
-       const char *dbpath;
+       char *dbpath;
        sqlite3_stmt *stmt;
 
        dbpath = getUserPkgParserDBPathUID(uid);
        if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
        if (ret != SQLITE_OK) {
                _LOGE("failed to open db: %d", ret);
+               free(dbpath);
                return PMINFO_R_ERROR;
        }
+       free(dbpath);
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -356,18 +360,20 @@ static int _pkginfo_get_certinfo(const char *pkgid, pkgmgr_certinfo_x *info)
 {
        int ret;
        sqlite3 *db;
-       const char *dbpath;
+       char *dbpath;
 
        /* open unified global cert db */
        dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
        if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
        if (ret != SQLITE_OK) {
                _LOGE("failed to open db: %d", ret);
+               free(dbpath);
                return PMINFO_R_ERROR;
        }
+       free(dbpath);
 
        ret = _pkginfo_get_certid(db, pkgid, info->cert_id);
        if (ret != PMINFO_R_OK) {
@@ -381,6 +387,8 @@ static int _pkginfo_get_certinfo(const char *pkgid, pkgmgr_certinfo_x *info)
                return ret;
        }
 
+       sqlite3_close_v2(db);
+
        return PMINFO_R_OK;
 }
 
@@ -587,7 +595,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
 {
        int ret;
        sqlite3 *db;
-       const char *dbpath;
+       char *dbpath;
        pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
 
        if (pkgid == NULL || handle == NULL) {
@@ -595,16 +603,20 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                return PMINFO_R_EINVAL;
        }
 
+       _check_create_cert_db();
+
        /* open unified global cert db */
        dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
        if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READWRITE);
        if (ret != SQLITE_OK) {
                _LOGE("failed to open db: %d", ret);
+               free(dbpath);
                return PMINFO_R_ERROR;
        }
+       free(dbpath);
 
        ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
@@ -613,8 +625,6 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                return PMINFO_R_ERROR;
        }
 
-       _check_create_cert_db(db);
-
        if (_pkginfo_save_cert_index_info(db, info->cert_info)) {
                _LOGE("failed to save cert index info, rollback now");
                sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
@@ -699,7 +709,7 @@ API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
 {
        int ret;
        sqlite3 *db;
-       const char *dbpath;
+       char *dbpath;
 
        if (pkgid == NULL) {
                _LOGE("invalid parameter");
@@ -711,11 +721,13 @@ API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
        if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READWRITE);
        if (ret != SQLITE_OK) {
                _LOGE("failed to open db: %d", ret);
+               free(dbpath);
                return PMINFO_R_ERROR;
        }
+       free(dbpath);
 
        ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {