Skip to content

Commit cf5bdb8

Browse files
Fixed memory leak reported in Bugzilla:
https://bugs.llvm.org/show_bug.cgi?id=41494 Freed th_cg_roots structure at exit from uber thread. Differential Revision: https://reviews.llvm.org/D60729 llvm-svn: 358572
1 parent 62e2472 commit cf5bdb8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,12 +3982,19 @@ static int __kmp_reset_root(int gtid, kmp_root_t *root) {
39823982

39833983
TCW_4(__kmp_nth,
39843984
__kmp_nth - 1); // __kmp_reap_thread will decrement __kmp_all_nth.
3985-
root->r.r_uber_thread->th.th_cg_roots->cg_nthreads--;
3985+
i = root->r.r_uber_thread->th.th_cg_roots->cg_nthreads--;
39863986
KA_TRACE(100, ("__kmp_reset_root: Thread %p decrement cg_nthreads on node %p"
39873987
" to %d\n",
39883988
root->r.r_uber_thread, root->r.r_uber_thread->th.th_cg_roots,
39893989
root->r.r_uber_thread->th.th_cg_roots->cg_nthreads));
3990-
3990+
if (i == 1) {
3991+
// need to free contention group structure
3992+
KMP_DEBUG_ASSERT(root->r.r_uber_thread ==
3993+
root->r.r_uber_thread->th.th_cg_roots->cg_root);
3994+
KMP_DEBUG_ASSERT(root->r.r_uber_thread->th.th_cg_roots->up == NULL);
3995+
__kmp_free(root->r.r_uber_thread->th.th_cg_roots);
3996+
root->r.r_uber_thread->th.th_cg_roots = NULL;
3997+
}
39913998
__kmp_reap_thread(root->r.r_uber_thread, 1);
39923999

39934000
// We canot put root thread to __kmp_thread_pool, so we have to reap it istead

0 commit comments

Comments
 (0)