Fix Savepoint destructor exception-safety and rollback bookkeeping#559
Merged
Conversation
The destructor caught only SQLite::Exception, so a std::bad_alloc thrown while building the "ROLLBACK TO SAVEPOINT ..." / "RELEASE SAVEPOINT ..." strings (or any other non-SQLite exception) escaped the implicitly noexcept destructor and called std::terminate. Broaden the handler to catch(...). Track an explicit mbRolledBack state so the destructor issues the minimum commands: when a rollback already happened (manual rollbackTo(), or the scope-exit path), it now does a single RELEASE instead of relying on SQLite tolerating a repeated ROLLBACK TO. The documented auto-rollback semantics are unchanged. Add a regression test covering a manual rollbackTo() followed by release(). Fixes SP-02 and SP-03 from the code review.
8cd214f to
afa51d3
Compare
The destructor caught only SQLite::Exception, so a std::bad_alloc thrown while building the "ROLLBACK TRANSACTION" string (or any other non-SQLite exception) escaped the implicitly noexcept destructor and called std::terminate. Broaden the handler to catch(...), matching the Savepoint fix (afa51d3). Fixes TXN-08 from the code review.
SRombauts
added a commit
that referenced
this pull request
Jun 30, 2026
SRombauts
added a commit
that referenced
this pull request
Jul 1, 2026
SRombauts
added a commit
that referenced
this pull request
Jul 1, 2026
The Transaction destructor already catches (...) since #559, and the T1 throw-from-destructor theme is resolved with it.
SRombauts
added a commit
that referenced
this pull request
Jul 1, 2026
SRombauts
added a commit
that referenced
this pull request
Jul 1, 2026
The Transaction destructor already catches (...) since #559, and the T1 throw-from-destructor theme is resolved with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two findings from the deep code review (SP-03, SP-02) in the
Savepointdestructor. The documented auto-rollback-on-scope-exit semantics are unchanged.SP-03 — destructor could call
std::terminate~Savepoint()caught onlySQLite::Exception. Building the"ROLLBACK TO SAVEPOINT " + msName/"RELEASE SAVEPOINT " + msNamestrings can throwstd::bad_alloc, and any non-SQLite::Exceptionthrown during cleanup would escape the implicitlynoexceptdestructor and terminate the process. The handler is nowcatch (...), matching the stated intent ("Never throw an exception in a destructor").SP-02 — no rolled-back state, fragile double-rollback
There was a single
mbReleasedflag and no notion of "already rolled back", so after a manualrollbackTo()(or on the normal scope-exit path) the destructor issued aROLLBACK TOand then aRELEASE, relying on SQLite tolerating a repeatedROLLBACK TO. A newmbRolledBackflag (set inrollbackTo()) lets the destructor do the minimum: skip the redundantROLLBACK TOand justRELEASE.Test plan
Savepoint.rollbackToThenReleasecovering a manualrollbackTo()followed byrelease()and a clean scope exit.SQLiteCpp_tests(MSVC, Debug);ctest -C Debug100% passed, including the existingSavepoint.commitRollbackandSavepoint.destructorSwallowsExceptiontests.No public API or behavioural change on the happy path; only the (previously UB-on-OOM) destructor error handling and the redundant-command path change.