Skip to content

fix: close database handles after failed open#330

Open
marcus-pousette wants to merge 1 commit into
rhashimoto:masterfrom
marcus-pousette:fix/failed-open-handle-cleanup-upstream
Open

fix: close database handles after failed open#330
marcus-pousette wants to merge 1 commit into
rhashimoto:masterfrom
marcus-pousette:fix/failed-open-handle-cleanup-upstream

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 16, 2026

Copy link
Copy Markdown

Checklist

  • I grant to recipients of this Project distribution a perpetual,
    non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
    derivative works of, publicly display, sublicense, and distribute this
    Contribution and such derivative works.
  • I certify that I am legally entitled to grant this license, and that this
    Contribution contains no content requiring a license from any third party.

Problem

SQLite can return a database handle even when sqlite3_open_v2 fails, and requires callers to close it. The wrapper currently tracks that failed handle, registers extension functions, and then throws before the caller can receive and release it.

See the sqlite3_open_v2 contract.

Change

  • Preserve sqlite3_errmsg before cleanup.
  • Best-effort close and untrack a handle returned by a failed open.
  • Register extension functions only after a successful open.

The focused regression test forces SQLITE_CANTOPEN with a non-null handle and proves that the original error is reported, the handle is closed and untracked, and extension registration is skipped.

@rhashimoto

Copy link
Copy Markdown
Owner

Thanks for the PR! That's a good catch.

Please fill out the contribution checklist that I prepended to your top-level PR message before I merge.

@rhashimoto rhashimoto added the response requested Further information is requested label Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

response requested Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants