[OpenMP][OMPT] Fix memory leak when using GCC compatibility code
authorJonathan Peyton <jonathan.l.peyton@intel.com>
Thu, 11 Aug 2022 16:13:01 +0000 (11:13 -0500)
committerJonathan Peyton <jonathan.l.peyton@intel.com>
Thu, 11 Aug 2022 20:26:09 +0000 (15:26 -0500)
Serialized parallels allocate lightweight task teams on the heap
but never free them in the corresponding join. This patch adds a wrapper
around the allocation (if ompt enabled) and also adds the corresponding
free in the join call.

Differential Revision: https://reviews.llvm.org/D131690

openmp/runtime/src/kmp_runtime.cpp

index b8d4705..a429ed1 100644 (file)
@@ -1947,12 +1947,14 @@ int __kmp_fork_call(ident_t *loc, int gtid,
         }
       } else if (call_context == fork_context_gnu) {
 #if OMPT_SUPPORT
-        ompt_lw_taskteam_t lwt;
-        __ompt_lw_taskteam_init(&lwt, master_th, gtid, &ompt_parallel_data,
-                                return_address);
+        if (ompt_enabled.enabled) {
+          ompt_lw_taskteam_t lwt;
+          __ompt_lw_taskteam_init(&lwt, master_th, gtid, &ompt_parallel_data,
+                                  return_address);
 
-        lwt.ompt_task_info.frame.exit_frame = ompt_data_none;
-        __ompt_lw_taskteam_link(&lwt, master_th, 1);
+          lwt.ompt_task_info.frame.exit_frame = ompt_data_none;
+          __ompt_lw_taskteam_link(&lwt, master_th, 1);
+        }
 // don't use lw_taskteam after linking. content was swaped
 #endif
 
@@ -2396,6 +2398,9 @@ void __kmp_join_call(ident_t *loc, int gtid
 
 #if OMPT_SUPPORT
     if (ompt_enabled.enabled) {
+      if (fork_context == fork_context_gnu) {
+        __ompt_lw_taskteam_unlink(master_th);
+      }
       __kmp_join_restore_state(master_th, parent_team);
     }
 #endif