Closed kuanchihwang closed 3 months ago
@kuanchihwang Excellent work in finding this memory leak! We're planning to release v8.1.0 later this week, and since this is a bug fix, I think it makes sense to set the base branch to release-v8.1.0
. Would you mind rebasing your PR branch on, say, the v8.0.0 tag? If you'd rather, I can handle the rebase and force-push the branch to your fork; just let me know what you'd prefer.
Yes, I have rebased this PR onto the release-v8.1.0
branch. The history is now linear again.
This PR fixes memory leaks due to duplicate
allocate
calls on pointers in the filesrc/core_atmosphere/inc/structs_and_variables.inc
. This file is auto-generated and theninclude
d bysrc/core_atmosphere/mpas_atm_core_interface.F
(among others) at compile time. No functional changes (NFC) are introduced by this PR.For example, in the auto-generated file
src/core_atmosphere/inc/structs_and_variables.inc
, there are code snippets similar to the following:The problem is that the
mpas_pool_create_pool
subroutine alreadyallocate
s the pointer in its arguments internally. Therefore, callingallocate
beforempas_pool_create_pool
actually causes memory leaks.Consider this minimal reproducible example (MRE):
Running the MRE with
valgrind --leak-check=full ./mem_leak_demo
produces the following report:Deleting the line with
allocate(mpas_pool)
in the MRE results in a clean report.