Skip to content

Release the wrapper when Open fails - #437

Closed
eric-hubbard wants to merge 1 commit into
ncruces:mainfrom
eric-hubbard:fix-open-leak
Closed

eric-hubbard wants to merge 1 commit into
ncruces:mainfrom
eric-hubbard:fix-open-leak

Conversation

@eric-hubbard

Copy link
Copy Markdown

Fixes #436.

newConn relied on the deferred c.Close() to clean up when sqlite3_open_v2 fails, but Conn.Close returns early when c.handle == 0, so c.wrp.Close() was never reached and each failed open leaked the connection's linear memory (a 256 MiB PROT_NONE reservation plus the committed initial pages).

The defer now closes the wrapper directly when there is no handle. Conn.Close is left as-is so closing a connection twice stays a no-op.

TestConn_Open_notfound_leak (Linux only, not parallel) counts /proc/self/maps entries across 20 failed opens. Without the fix it fails with mappings grew from 58 to 98 after 20 failed opens; with it, the count is flat. go test . ./tests/ ./driver/... passes on linux/amd64 and darwin/arm64.

newConn relied on the deferred Conn.Close to clean up when
sqlite3_open_v2 fails, but Close returns early when there is no
handle, so the wrapper and its linear memory were never released.

Fixes ncruces#436
@ncruces ncruces closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed Open leaks the connection's linear memory reservation

2 participants