SQLite Forum

segmentation fault when closing a database from within a transaction
Login

segmentation fault when closing a database from within a transaction

(1) By Poor Yorick (pooryorick) on 2021-09-14 13:43:07 [source]

The following Tcl script script triggers a segmentation fault when run with a debugging build of sqlite and a debugging build of Tcl:

package require sqlite3
sqlite3 db :memory:
db transaction {db close}

-- Poor Yorick

(2) By Warren Young (wyoung) on 2021-09-14 14:15:05 in reply to 1 [link] [source]

Okay, yes, good, fix the crash.

...but what did you expect it to do? This code says "close the database and then finalize the transaction." You can't finalize something via a closed conn.

(3) By Poor Yorick (pooryorick) on 2021-09-14 14:58:02 in reply to 2 [link] [source]

The transaction context be detected and finalized in the process of closing the database.

(4.1) By Warren Young (wyoung) on 2021-09-14 17:33:49 edited from 4.0 in reply to 3 [link] [source]

I'd expect transactions left open on DB conn close to be rolled back, having not received the "COMMIT" call which can now never come by the very fact of the DB conn being closed now.

If closing the DB conn auto-commits all still-open transactions under the Tcl SQLite binding, I'd call that a bug, not a feature. The semantic meaning of transactions is that those not explicitly committed get rolled back, but once again, that can't happen with the conn closed.

(5) By Larry Brasfield (larrybr) on 2021-09-16 15:22:17 in reply to 1 [link] [source]

Thanks for reporting this. Dan Kennedy's fix is at https://www.sqlite.org/src/info/e54a33ce56432b23 .