[Openmp-commits] [openmp] r358572 - Fixed memory leak reported in Bugzilla:

Andrey Churbanov via Openmp-commits openmp-commits at lists.llvm.org
Wed Apr 17 03:44:28 PDT 2019


Author: achurbanov
Date: Wed Apr 17 03:44:28 2019
New Revision: 358572

URL: http://llvm.org/viewvc/llvm-project?rev=358572&view=rev
Log:
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

Modified:
    openmp/trunk/runtime/src/kmp_runtime.cpp

Modified: openmp/trunk/runtime/src/kmp_runtime.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.cpp?rev=358572&r1=358571&r2=358572&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.cpp (original)
+++ openmp/trunk/runtime/src/kmp_runtime.cpp Wed Apr 17 03:44:28 2019
@@ -3982,12 +3982,19 @@ static int __kmp_reset_root(int gtid, km
 
   TCW_4(__kmp_nth,
         __kmp_nth - 1); // __kmp_reap_thread will decrement __kmp_all_nth.
-  root->r.r_uber_thread->th.th_cg_roots->cg_nthreads--;
+  i = root->r.r_uber_thread->th.th_cg_roots->cg_nthreads--;
   KA_TRACE(100, ("__kmp_reset_root: Thread %p decrement cg_nthreads on node %p"
                  " to %d\n",
                  root->r.r_uber_thread, root->r.r_uber_thread->th.th_cg_roots,
                  root->r.r_uber_thread->th.th_cg_roots->cg_nthreads));
-
+  if (i == 1) {
+    // need to free contention group structure
+    KMP_DEBUG_ASSERT(root->r.r_uber_thread ==
+                     root->r.r_uber_thread->th.th_cg_roots->cg_root);
+    KMP_DEBUG_ASSERT(root->r.r_uber_thread->th.th_cg_roots->up == NULL);
+    __kmp_free(root->r.r_uber_thread->th.th_cg_roots);
+    root->r.r_uber_thread->th.th_cg_roots = NULL;
+  }
   __kmp_reap_thread(root->r.r_uber_thread, 1);
 
   // We canot put root thread to __kmp_thread_pool, so we have to reap it istead




More information about the Openmp-commits mailing list