8297911: Memory leak in JfrUpcalls::on_retransform

Reviewed-by: mgronlun
This commit is contained in:
Justin King 2022-12-02 11:31:19 +00:00 committed by Markus Grönlund
parent 5c0ff26f32
commit 1376f33011
2 changed files with 14 additions and 19 deletions

View File

@ -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");

View File

@ -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
}