From: dyamy-lee Date: Tue, 12 Mar 2024 08:03:29 +0000 (+0900) Subject: Add NULL checking X-Git-Tag: accepted/tizen/unified/20240315.111155~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07f6bccebf7218f1088b55290c4ef0c2a3bf9d13;p=platform%2Fcore%2Fuifw%2Fvoice-control.git Add NULL checking NULL_AFTER_DEREF Alarm needs checking NULL. So, it added null check before using db_handle variable. Change-Id: I40d4e166a86df23b3ffce6ba7f41c14ae3b443aa --- diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 6250dfb..6afb62b 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1529,6 +1529,11 @@ static int __vc_db_open_db_for_daemon(const char* path, sqlite3** db_handle) return VC_DB_ERROR_OPERATION_FAILED; } + if (*db_handle == NULL) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db, path = %s, ret(%d)", path, ret); + return VC_DB_ERROR_OPERATION_FAILED; + } + ret = sqlite3_exec(*db_handle, "PRAGMA integrity_check", 0, 0, 0); if (SQLITE_OK != ret) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB for daemon"); @@ -1579,17 +1584,16 @@ static int __vc_db_open_db_for_daemon(const char* path, sqlite3** db_handle) __vc_db_commit_transaction(*db_handle); } - if (*db_handle) { - char* err_msg = NULL; - static const char* sql = "PRAGMA journal_mode = WAL"; - int ret = sqlite3_exec(*db_handle, sql, NULL, NULL, &err_msg); - if (ret != SQLITE_OK) { - SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_exec returned %d: %s", ret, err_msg); - sqlite3_free(err_msg); - err_msg = NULL; - return VC_DB_ERROR_OPERATION_FAILED; - } + char* err_msg = NULL; + static const char* sql = "PRAGMA journal_mode = WAL"; + ret = sqlite3_exec(*db_handle, sql, NULL, NULL, &err_msg); + if (ret != SQLITE_OK) { + SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_exec returned %d: %s", ret, err_msg); + sqlite3_free(err_msg); + err_msg = NULL; + return VC_DB_ERROR_OPERATION_FAILED; } + return VC_DB_ERROR_NONE; }