mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
sqlite: avoid resetting a finalized statement
run() and get() reset a cached statement pointer on exit. Throwing an error can run an Error.prototype setter that closes the database and frees it. Reset through the Statement, which Finalize() clears. Assisted-by: Claude Code Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: https://github.com/nodejs/node/pull/67557 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
This commit is contained in:
1 parent
7bfa50aa94
commit
f0eb690cf1
2 files changed
+65
-2
No files matched your search
+4
-2
@@ -3835,9 +3835,10 @@ MaybeLocal<Object> StatementExecutionHelper::Run(Environment* env,
|
||||
// Declared before the reset below so that it outlives it: sqlite3_reset()
|
||||
// can run JavaScript through an aggregate's xFinal.
|
||||
SteppingStatementGuard stepping(db, stmt);
|
||||
// Throwing can run JS that closes the database and frees `stmt`.
|
||||
bool needs_reset = true;
|
||||
auto reset = OnScopeLeave([&]() {
|
||||
if (needs_reset) sqlite3_reset(stmt);
|
||||
if (needs_reset) sqlite3_reset(statement->statement_.get());
|
||||
});
|
||||
|
||||
int step_r = sqlite3_step(stmt);
|
||||
@@ -3923,9 +3924,10 @@ MaybeLocal<Value> StatementExecutionHelper::Get(Environment* env,
|
||||
// Declared before the reset below so that it outlives it: sqlite3_reset()
|
||||
// can run JavaScript through an aggregate's xFinal.
|
||||
SteppingStatementGuard stepping(db, stmt);
|
||||
// Throwing can run JS that closes the database and frees `stmt`.
|
||||
bool needs_reset = true;
|
||||
auto reset = OnScopeLeave([&]() {
|
||||
if (needs_reset) sqlite3_reset(stmt);
|
||||
if (needs_reset) sqlite3_reset(statement->statement_.get());
|
||||
});
|
||||
|
||||
int r = sqlite3_step(stmt);
|
||||
|
||||
Reference in new issue
Block a user