summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-22 22:02:18 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-22 22:02:18 +0000
commita7ec1294ceb761f5275ec9219fc85f7c30c95552 (patch)
tree3c7109bd2a770f2a2ef947b327bfcf3dda00518e /sql
parentad635b110cbc859e863672a41f1e697d1a8d603d (diff)
downloadchromium_src-a7ec1294ceb761f5275ec9219fc85f7c30c95552.zip
chromium_src-a7ec1294ceb761f5275ec9219fc85f7c30c95552.tar.gz
chromium_src-a7ec1294ceb761f5275ec9219fc85f7c30c95552.tar.bz2
[sql] Serialize calls to sqlite3_initialize().
sqlite3_initialize() uses double-check locking, and is thus prone to data races. BUG=248101 Review URL: https://chromiumcodereview.appspot.com/19000007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212984 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r--sql/connection.cc19
-rw-r--r--sql/sql.gyp1
2 files changed, 20 insertions, 0 deletions
diff --git a/sql/connection.cc b/sql/connection.cc
index 4550b0e..c10f5a7 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -8,6 +8,7 @@
#include "base/files/file_path.h"
#include "base/file_util.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
@@ -15,6 +16,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/synchronization/lock.h"
#include "sql/statement.h"
#include "third_party/sqlite/sqlite3.h"
@@ -109,6 +111,20 @@ bool ValidAttachmentPoint(const char* attachment_point) {
return true;
}
+// SQLite automatically calls sqlite3_initialize() lazily, but
+// sqlite3_initialize() uses double-checked locking and thus can have
+// data races.
+//
+// TODO(shess): Another alternative would be to have
+// sqlite3_initialize() called as part of process bring-up. If this
+// is changed, remove the dynamic_annotations dependency in sql.gyp.
+base::LazyInstance<base::Lock>::Leaky
+ g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER;
+void InitializeSqlite() {
+ base::AutoLock lock(g_sqlite_init_lock.Get());
+ sqlite3_initialize();
+}
+
} // namespace
namespace sql {
@@ -799,6 +815,9 @@ bool Connection::OpenInternal(const std::string& file_name,
return false;
}
+ // Make sure sqlite3_initialize() is called before anything else.
+ InitializeSqlite();
+
// If |poisoned_| is set, it means an error handler called
// RazeAndClose(). Until regular Close() is called, the caller
// should be treating the database as open, but is_open() currently
diff --git a/sql/sql.gyp b/sql/sql.gyp
index 4b16673..1ececce 100644
--- a/sql/sql.gyp
+++ b/sql/sql.gyp
@@ -13,6 +13,7 @@
'dependencies': [
'../base/base.gyp:base',
'../third_party/sqlite/sqlite.gyp:sqlite',
+ '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
],
'export_dependent_settings': [
'../base/base.gyp:base',