Bug 225881 - Make sure SQLiteStatement objects get destroyed before the database is closed
Summary: Make sure SQLiteStatement objects get destroyed before the database is closed
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-17 12:59 PDT by Chris Dumez
Modified: 2021-05-18 08:36 PDT (History)
6 users (show)

See Also:


Attachments
Patch (7.74 KB, patch)
2021-05-17 13:47 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (9.15 KB, patch)
2021-05-17 20:58 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (9.09 KB, patch)
2021-05-18 07:37 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-05-17 12:59:11 PDT
Make sure SQLiteStatement objects get destroyed before the database is closed. There are 2 issues with destroying a SQLiteStatement after a database is closed:
1. The underlying call to close the sqlite database will fail if the database still has statements and we will leak the database.
2. SQLiteStatement has a reference to the database so it cannot outlive the SQLiteDatabase.
Comment 1 Chris Dumez 2021-05-17 13:47:35 PDT
Created attachment 428862 [details]
Patch
Comment 2 Chris Dumez 2021-05-17 20:58:58 PDT
Created attachment 428910 [details]
Patch
Comment 3 Darin Adler 2021-05-17 23:07:01 PDT
Comment on attachment 428910 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=428910&action=review

> Source/WebCore/platform/sql/SQLiteDatabase.cpp:225
> +        ASSERT_WITH_MESSAGE(!m_statementCount, "All SQLiteTransaction objects should be destroyed before closing the database");

"should" -> "must"

> Source/WebCore/platform/sql/SQLiteDatabase.cpp:727
> +void SQLiteDatabase::incrementStatementCount()
> +{
> +#if ASSERT_ENABLED
> +    ++m_statementCount;
> +#endif
> +}
> +
> +void SQLiteDatabase::decrementStatementCount()
> +{
> +#if ASSERT_ENABLED
> +    ASSERT(m_statementCount);
> +    --m_statementCount;
> +#endif
> +}

When asserts are disabled you’d want this empty function inlined. Can we put these in the header?
Comment 4 Chris Dumez 2021-05-18 07:37:07 PDT
Created attachment 428935 [details]
Patch
Comment 5 EWS 2021-05-18 08:35:10 PDT
Committed r277653 (237859@main): <https://commits.webkit.org/237859@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 428935 [details].
Comment 6 Radar WebKit Bug Importer 2021-05-18 08:36:22 PDT
<rdar://problem/78156408>