JDK-6496392 : attach_current_thread can leak JavaThread object (and associated data structures) if an error occurs
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-11-22
  • Updated: 2012-10-08
  • Resolved: 2007-06-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u4Fixed 7Fixed hs10Fixed
In attach_current_thread we reach a point where we "new" a JavaThread object for the current thread. After that there are two places where we return JNI_ERR, the first of which does not clean up the JavaThread that was created.
Similarly create_vm can also leak the JavaThread and associated structures.

EVALUATION Submitter is correct.

SUGGESTED FIX *** /tmp/geta12122 Wed Nov 22 16:16:36 2006 --- jni.cpp Wed Nov 22 16:16:29 2006 *************** *** 3335,3342 **** thread->record_stack_base_and_size(); thread->initialize_thread_local_storage(); ! if (!os::create_attached_thread(thread)) ! return JNI_ERR; // Crucial that we do not have a safepoint check for this thread, since it has // not been added to the Thread list yet. --- 3335,3344 ---- thread->record_stack_base_and_size(); thread->initialize_thread_local_storage(); ! if (!os::create_attached_thread(thread)) { ! delete thread; ! return JNI_ERR; ! }