Skip to content

Commit 60d0fd4

Browse files
committed
Potential memory leak with the JVMTI wallclock sampler
1 parent 793d42c commit 60d0fd4

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,19 @@ void WallClockJVMTI::timerLoop() {
173173

174174
bool do_filter = Profiler::instance()->threadFilter()->enabled();
175175
int self = OS::threadId();
176+
JNIEnv *env = VM::jni();
176177

177178
for (int i = 0; i < threads_count; i++) {
178179
jthread thread = threads_ptr[i];
179180
if (thread != nullptr) {
180181
ddprof::VMThread* nThread = static_cast<ddprof::VMThread*>(VMThread::fromJavaThread(jni, thread));
181-
if (nThread == nullptr) {
182-
continue;
183-
}
184-
int tid = nThread->osThreadId();
185-
if (tid != self && (!do_filter || Profiler::instance()->threadFilter()->accept(tid))) {
186-
threads.push_back({nThread, thread});
182+
if (nThread != nullptr) {
183+
int tid = nThread->osThreadId();
184+
if (tid != self && (!do_filter || Profiler::instance()->threadFilter()->accept(tid))) {
185+
threads.push_back({nThread, thread});
186+
}
187187
}
188+
env->DeleteLocalRef(thread);
188189
}
189190
}
190191
jvmti->Deallocate((unsigned char*)threads_ptr);

0 commit comments

Comments
 (0)