Fix the possibility of a memory leak 11/209911/4
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 12 Jul 2019 08:20:23 +0000 (17:20 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 16 Jul 2019 01:00:01 +0000 (10:00 +0900)
The sqlite3_open_v2() function may have a db handle
,even if even if an error occurs.

Change-Id: Ibe402d33984f833ea79556eece734b7cc349da35
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
parser/src/pkgmgr_parser_db.c
src/pkgmgrinfo_private.c
tool/pkg-db-recovery.c

index 6829c08..43b7467 100644 (file)
@@ -541,6 +541,7 @@ API int pkgmgr_parser_initialize_parser_db(uid_t uid)
                        SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("open db failed: %d", ret);
+               sqlite3_close_v2(db);
                return PM_PARSER_R_ERROR;
        }
 
@@ -577,6 +578,7 @@ API int pkgmgr_parser_initialize_cert_db(void)
                        SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("open db failed: %d", ret);
+               sqlite3_close_v2(db);
                return PM_PARSER_R_ERROR;
        }
 
@@ -647,8 +649,10 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
        int persist_wal = 1;
 
        ret = sqlite3_open_v2(path, db, flags, NULL);
-       if (ret != SQLITE_OK)
+       if (ret != SQLITE_OK) {
+               sqlite3_close_v2(*db);
                return ret;
+       }
 
        ret = sqlite3_busy_handler(*db, __db_busy_handler, (void *)path);
        if (ret != SQLITE_OK) {
index 7ed3fa5..58ee0e7 100644 (file)
@@ -575,8 +575,10 @@ int __open_db(const char *path, sqlite3 **db, int flags)
        int no_checkpoint = 1;
 
        ret = sqlite3_open_v2(path, db, flags, NULL);
-       if (ret != SQLITE_OK)
+       if (ret != SQLITE_OK) {
+               sqlite3_close_v2(*db);
                return ret;
+       }
 
        ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
        if (ret != SQLITE_OK) {
index 4d92612..f031878 100644 (file)
@@ -108,6 +108,7 @@ static bool __integrity_check(const char *db_path)
                        SQLITE_OPEN_READWRITE, NULL);
        if (ret != SQLITE_OK) {
                LOGE("Failed to open db");
+               sqlite3_close_v2(db);
                return false;
        }