sqlite: introduces RAII ownership for sqlite3_stmt#62419
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62419 +/- ##
==========================================
- Coverage 92.01% 90.24% -1.77%
==========================================
Files 379 739 +360
Lines 170129 241673 +71544
Branches 26090 45542 +19452
==========================================
+ Hits 156544 218106 +61562
- Misses 13293 15110 +1817
- Partials 292 8457 +8165
🚀 New features to boost your workflow:
|
louwers
left a comment
There was a problem hiding this comment.
Can RAII be used instead?
Well, we could use |
6a3fa74 to
f83c2f6
Compare
f83c2f6 to
ea61e53
Compare
|
@nodejs/sqlite Bump, I did a safety improvement by implementing RAII for |
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
ea61e53 to
78e32bc
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a resource-management bug in the SQLite sync binding where a prepared sqlite3_stmt could be leaked (and a nullptr inserted into db->statements_) when StatementSync::Create fails to allocate the JS wrapper object (e.g., OOM).
Changes:
- Introduces RAII ownership for
sqlite3_stmtviaStatementPtr(DeleteFnPtr+FinalizeStatement). - Updates
StatementSyncto own the prepared statement withStatementPtrand uses.get()at call sites. - Ensures
DatabaseSync::Preparereturns early whenStatementSync::Createfails, preventingnullptrinsertion intodb->statements_.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/node_sqlite.h | Adds FinalizeStatement + StatementPtr alias and updates StatementSync API/member to use RAII for sqlite3_stmt. |
| src/node_sqlite.cc | Transfers statement ownership with StatementPtr, resets via RAII, and guards against Create() failure to avoid leaks/null insertion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
If
StatementSync::Createfails to allocate a JS object (OOM), thesqlite3_stmtprepared bysqlite3_prepare_v2was leaked and a null pointer was silently inserted intodb->statements_