Skip to content

Fix native memory leak in RocksJava thread-local comparator buffers - #15127

Open
Shikha-code36 wants to merge 1 commit into
facebook:mainfrom
Shikha-code36:fix-comparator-threadlocal-buf-leak
Open

Shikha-code36 wants to merge 1 commit into
facebook:mainfrom
Shikha-code36:fix-comparator-threadlocal-buf-leak

Conversation

@Shikha-code36

Copy link
Copy Markdown

Fixes a native memory leak in RocksJava: when a Comparator is configured with
thread-local reusable buffers (ReusedSynchronisationType.THREAD_LOCAL), the
native ThreadLocalBuf wrapper allocated per thread in
ComparatorJniCallback::GetBuffer was never freed.

The ThreadLocalPtr unref handler correctly released the JNI global reference
and the direct-buffer backing memory, but never deleted the ThreadLocalBuf
object itself:

UnrefHandler unref = [](void* ptr) {
  ThreadLocalBuf* tlb = reinterpret_cast<ThreadLocalBuf*>(ptr);
  ...
  _env->DeleteGlobalRef(tlb->jbuf);
  JniUtil::releaseJniEnv(tlb->jvm, attached_thread);
  // tlb itself was never deleted
};

Fixes #14975

The ThreadLocalPtr unref handler for Comparator thread-local reused
buffers released the JNI global ref and direct-buffer memory but
never deleted the ThreadLocalBuf wrapper itself, leaking it for
every thread that used a comparator configured with
ReusedSynchronisationType.THREAD_LOCAL.

Fixes facebook#14975
@meta-cla

meta-cla Bot commented Aug 19, 2026

Copy link
Copy Markdown

Hi @Shikha-code36!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Aug 19, 2026
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.

Comparator thread-local reusable buffers do not delete their native wrapper

1 participant