Skip to content

Frees the env when open fails - #45

Merged
kasperisager merged 3 commits into
holepunchto:mainfrom
tur-nr:fix/open-env-leak
Nov 13, 2026
Merged

kasperisager merged 3 commits into
holepunchto:mainfrom
tur-nr:fix/open-env-leak

Conversation

@tur-nr

@tur-nr tur-nr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Problem

rocksdb__on_open hands the composite env to options.env with release(), and only rocksdb__on_close deletes it. When the open fails db->handle stays null, so close returns early and the env leaks on every failed open. rocksdb-native's ASan job caught it once a test opened a locked database (holepunchto/rocksdb-native#128).

Proposal

  • Keep the env in its unique_ptr until the open succeeds, then release it to the database as before
  • A failed open frees it on return, whether DB::Open fails or the wal_filter_prefixes check rejects it first

Tests

open-locked opens a database, then opens the same path again so the second DB::Open fails on the lock.

CI here doesn't enable leak detection, so this was checked locally with leaks --atExit on a non-sanitized debug build: open-locked and read-only-wal-filter both report 3 leaks (528 bytes, rooted at the CompositeEnvWrapper from NewCompositeEnv) without the change and 0 with it. The full suite passes under ASan, so freeing the env after a failed open doesn't trip a use-after-free.

@tur-nr
tur-nr marked this pull request as ready for review November 13, 2026 06:21
@tur-nr
tur-nr requested a review from a team November 13, 2026 06:21
Comment thread src/rocksdb.cc Resolved
Comment thread src/rocksdb.cc Resolved
Comment thread test/open-locked.c Resolved
Co-authored-by: Kasper Isager Dalsgarð <kasperisager@hey.com>
@kasperisager
kasperisager merged commit 2030346 into holepunchto:main Nov 13, 2026
13 checks passed
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.

2 participants