Skip to content

Commit

Permalink
8297911: Memory leak in JfrUpcalls::on_retransform
Browse files Browse the repository at this point in the history
Reviewed-by: mgronlun
  • Loading branch information
jcking authored and Markus Grönlund committed Dec 2, 2022
1 parent 5c0ff26 commit 1376f33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
29 changes: 13 additions & 16 deletions src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,22 +1524,19 @@ static ClassFileStream* retransform_bytes(const Klass* existing_klass, const Cla
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
jint size_of_new_bytes = 0;
unsigned char* new_bytes = NULL;
{
ResourceMark rm(THREAD);
const ClassFileStream* const stream = parser.clone_stream();
assert(stream != NULL, "invariant");
const jclass clazz = static_cast<jclass>(JfrJavaSupport::local_jni_handle(existing_klass->java_mirror(), THREAD));
JfrUpcalls::on_retransform(JfrTraceId::load_raw(existing_klass),
clazz,
stream->length(),
stream->buffer(),
&size_of_new_bytes,
&new_bytes,
THREAD);
JfrJavaSupport::destroy_local_jni_handle(clazz);
if (has_pending_exception(THREAD)) {
return NULL;
}
const ClassFileStream* const stream = parser.clone_stream();
assert(stream != NULL, "invariant");
const jclass clazz = static_cast<jclass>(JfrJavaSupport::local_jni_handle(existing_klass->java_mirror(), THREAD));
JfrUpcalls::on_retransform(JfrTraceId::load_raw(existing_klass),
clazz,
stream->length(),
stream->buffer(),
&size_of_new_bytes,
&new_bytes,
THREAD);
JfrJavaSupport::destroy_local_jni_handle(clazz);
if (has_pending_exception(THREAD)) {
return NULL;
}
assert(new_bytes != NULL, "invariant");
assert(size_of_new_bytes > 0, "invariant");
Expand Down
4 changes: 1 addition & 3 deletions src/hotspot/share/jfr/jni/jfrUpcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ void JfrUpcalls::on_retransform(jlong trace_id,
CHECK);
assert(new_byte_array != NULL, "invariant");
assert(new_bytes_length > 0, "invariant");
// memory space must be malloced as mtInternal
// as it will be deallocated by JVMTI routines
unsigned char* const new_bytes = (unsigned char* const)os::malloc(new_bytes_length, mtInternal);
unsigned char* const new_bytes = NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(THREAD, unsigned char, new_bytes_length);
if (new_bytes == NULL) {
log_error_and_throw_oom(new_bytes_length, THREAD); // unwinds
}
Expand Down

1 comment on commit 1376f33

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.