Skip to content

Fix native ReadOptions leak in RocksDB.close() (Java) - #15069

Open
taimoor789 wants to merge 1 commit into
facebook:mainfrom
taimoor789:my-first-fix
Open

Fix native ReadOptions leak in RocksDB.close() (Java)#15069
taimoor789 wants to merge 1 commit into
facebook:mainfrom
taimoor789:my-first-fix

Conversation

@taimoor789

Copy link
Copy Markdown

Summary

RocksDB.close() disposes owned column family handles and its own native handle, but never releases defaultReadOptions_, the ReadOptions object eagerly created in the field declaration and used internally by newIterator(). This leaks one native ReadOptions object per opened RocksDB instance for the lifetime of the JVM, since there is no finalizer or Cleaner fallback anywhere in the RocksObject hierarchy, an explicit close() call is the only path to native cleanup, and this one was never wired up.

Fix

Added defaultReadOptions_.close() inside close()'s existing cleanup block, alongside disposeInternal().

Testing

Added closeReleasesDefaultReadOptions to RocksDBTest.java, asserting defaultReadOptions_.isOwningHandle() transitions from true to false across a close() call. Full Java suite passes (1241 tests, 0 failures).

Fixes #15036

RocksDB.close() disposed owned column family handles and its own
native handle, but never released defaultReadOptions_, leaking one
native ReadOptions object per opened DB instance for the life of the
JVM. Fixes facebook#15036.
@meta-cla meta-cla Bot added the CLA Signed label Aug 7, 2026

@mjsax mjsax left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing a fix! -- I am not a RocksDB maintainer, but seems to be straightforward. LGTM.

Hope this can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java] RocksDB.close() never closes defaultReadOptions_, leaking a native ReadOptions per DB instance

2 participants