Skip to content

Commit 58d9b7e

Browse files
authored
Fix JVMTI memory leak in FlightRecorder::flush (#325)
Fix JVMTI memory leak in FlightRecorder::flush 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: jaroslav.bachorik <jaroslav.bachorik@datadoghq.com>
1 parent 58b4dca commit 58d9b7e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

ddprof-lib/src/main/cpp/flightRecorder.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,18 +1534,19 @@ void FlightRecorder::flush() {
15341534
jvmtiEnv* jvmti = VM::jvmti();
15351535
JNIEnv* env = VM::jni();
15361536

1537-
jclass** classes = NULL;
1537+
jclass* classes = NULL;
15381538
jint count = 0;
15391539
// obtaining the class list will create local refs to all loaded classes,
15401540
// effectively preventing them from being unloaded while flushing
1541-
jvmtiError err = jvmti->GetLoadedClasses(&count, classes);
1541+
jvmtiError err = jvmti->GetLoadedClasses(&count, &classes);
15421542
rec->switchChunk(-1);
15431543
if (!err) {
1544-
// deallocate all loaded classes
1544+
// delete all local references
15451545
for (int i = 0; i < count; i++) {
15461546
env->DeleteLocalRef((jobject) classes[i]);
1547-
jvmti->Deallocate((unsigned char*) classes[i]);
15481547
}
1548+
// deallocate the class array
1549+
jvmti->Deallocate((unsigned char*) classes);
15491550
}
15501551
}
15511552
}

0 commit comments

Comments
 (0)