SQL: change Database::db_ to a raw_ptr
SQLite allocates this pointer via malloc which should be intercepted by PartitionAlloc. Change-Id: Ia4dae3e1557ed03e6753a0f1528d856850905a8e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5247316 Commit-Queue: Evan Stade <estade@chromium.org> Reviewed-by: Keishi Hattori <keishi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1255118}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
74ec3c23f4
commit
ae04e197b3
@ -393,16 +393,15 @@ void Database::CloseInternal(bool forced) {
|
||||
std::move(memory_dump_provider_));
|
||||
}
|
||||
|
||||
auto sqlite_result_code = ToSqliteResultCode(sqlite3_close(db_));
|
||||
sqlite3* raw_db = db_;
|
||||
db_ = nullptr;
|
||||
auto sqlite_result_code = ToSqliteResultCode(sqlite3_close(raw_db));
|
||||
|
||||
DCHECK_NE(sqlite_result_code, SqliteResultCode::kBusy)
|
||||
<< "sqlite3_close() called while prepared statements are still alive";
|
||||
DCHECK_EQ(sqlite_result_code, SqliteResultCode::kOk)
|
||||
<< "sqlite3_close() failed in an unexpected way: " << GetErrorMessage();
|
||||
|
||||
// The reset must happen after the DCHECKs above. GetErrorMessage() needs a
|
||||
// valid `db_` value.
|
||||
db_ = nullptr;
|
||||
<< "sqlite3_close() failed in an unexpected way: "
|
||||
<< sqlite3_errmsg(raw_db);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1833,18 +1832,18 @@ bool Database::OpenInternal(const std::string& db_file_path,
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
}
|
||||
|
||||
sqlite3* db = nullptr;
|
||||
auto sqlite_result_code = ToSqliteResultCode(sqlite3_open_v2(
|
||||
uri_file_path.c_str(), &db_, open_flags, /*zVfs=*/nullptr));
|
||||
if (sqlite_result_code != SqliteResultCode::kOk) {
|
||||
uri_file_path.c_str(), &db, open_flags, /*zVfs=*/nullptr));
|
||||
if (sqlite_result_code == SqliteResultCode::kOk) {
|
||||
db_ = db;
|
||||
} else {
|
||||
// sqlite3_open_v2() will usually create a database connection handle, even
|
||||
// if an error occurs (see https://www.sqlite.org/c3ref/open.html).
|
||||
// Therefore, we'll clear `db_` immediately - particularly before triggering
|
||||
// an error callback which may check whether a database connection exists.
|
||||
if (db_) {
|
||||
if (db) {
|
||||
// Deallocate resources allocated during the failed open.
|
||||
// See https://www.sqlite.org/c3ref/close.html.
|
||||
sqlite3_close(db_);
|
||||
db_ = nullptr;
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
OnSqliteError(ToSqliteErrorCode(sqlite_result_code), nullptr,
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/gtest_prod_util.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/raw_ptr_exclusion.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/sequence_checker.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
@ -960,9 +959,7 @@ class COMPONENT_EXPORT(SQL) Database {
|
||||
|
||||
// The actual sqlite database. Will be null before Init has been called or if
|
||||
// Init resulted in an error.
|
||||
// This field is not a raw_ptr<> because it was filtered by the rewriter for:
|
||||
// #addr-of
|
||||
RAW_PTR_EXCLUSION sqlite3* db_ = nullptr;
|
||||
raw_ptr<sqlite3> db_ = nullptr;
|
||||
|
||||
// TODO(shuagga@microsoft.com): Make `options_` const after removing all
|
||||
// setters.
|
||||
|
Reference in New Issue
Block a user