From 56f36f85e029d6947d07d7d174801104785149a7 Mon Sep 17 00:00:00 2001 From: Jonathan Peyton Date: Thu, 11 Aug 2022 11:13:01 -0500 Subject: [PATCH] [OpenMP][OMPT] Fix memory leak when using GCC compatibility code 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 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp index b8d4705..a429ed1 100644 --- a/openmp/runtime/src/kmp_runtime.cpp +++ b/openmp/runtime/src/kmp_runtime.cpp @@ -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 -- 2.7.4