summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 20:40:48 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 20:40:48 +0000
commit4b350056920e397cbafe4259356136b5a81e6da0 (patch)
tree47883a24f4328a3dc3463bf1154d066c03166e0e /sql
parent08a59f680b85cf0806ecfb837b0893c8fa6dd489 (diff)
downloadchromium_src-4b350056920e397cbafe4259356136b5a81e6da0.zip
chromium_src-4b350056920e397cbafe4259356136b5a81e6da0.tar.gz
chromium_src-4b350056920e397cbafe4259356136b5a81e6da0.tar.bz2
Close out statement refs before closing database.
The existing code DCHECKs that all statement handles are closed, but if any statements handles are open, they have a weak reference which can end up referring to a deallocated Connection instance. Additionally, that change allows the code to reach DeleteSessionCookies() without crashing, so add a guard there. BUG=111376 TEST=fewer crashes. Review URL: http://codereview.chromium.org/9402035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r--sql/connection.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/sql/connection.cc b/sql/connection.cc
index bebf68a..58819a7 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -108,8 +108,17 @@ bool Connection::OpenInMemory() {
}
void Connection::Close() {
+ // sqlite3_close() needs all prepared statements to be finalized.
+ // Release all cached statements, then assert that the client has
+ // released all statements.
statement_cache_.clear();
DCHECK(open_statements_.empty());
+
+ // Additionally clear the prepared statements, because they contain
+ // weak references to this connection. This case has come up when
+ // error-handling code is hit in production.
+ ClearCache();
+
if (db_) {
// TODO(shess): Some additional code to debug http://crbug.com/95527 .
// If you are reading this due to link errors or something, it can
@@ -125,6 +134,8 @@ void Connection::Close() {
// prevent optimization.
CHECK_LT(nTouched, 1000*1000*1000U);
#endif
+
+ // TODO(shess): Histogram for failure.
sqlite3_close(db_);
db_ = NULL;
}