Skip to content

Commit

Permalink
Merge branch 'develop-fix-memory-leaks' into release-v8.1.0 (PR #1160)
Browse files Browse the repository at this point in the history
This merge fixes memory leaks due to duplicate allocate calls on pointers in the
file structs_and_variables.inc. This file is auto-generated and then included by,
e.g., src/core_atmosphere/mpas_atm_core_interface.F at compile time. No
functional changes are introduced by this merge.

For example, in the auto-generated file
src/core_atmosphere/inc/structs_and_variables.inc, there are code snippets
similar to the following:

  subroutine atm_generate_pool_mesh(block, structPool, dimensionPool, packagePool)

  ! ... (Unrelated lines omitted) ...

        type(mpas_pool_type), pointer :: newSubPool

  ! ... (Unrelated lines omitted) ...

        allocate(newSubPool)
        call mpas_pool_create_pool(newSubPool)
        call mpas_pool_add_subpool(structPool, 'mesh', newSubPool)
        call mpas_pool_add_subpool(block % allStructs, 'mesh', newSubPool)

  ! ... (Unrelated lines omitted) ...

  end subroutine atm_generate_pool_mesh

The problem is that the mpas_pool_create_pool subroutine already allocates the
pointer in its arguments internally. Therefore, calling allocate before
mpas_pool_create_pool actually causes memory leaks.

The fix adopted in this merge is to simply remove the generation of the
'allocate' calls in the 'structs_and_variables.inc' file for each core.
  • Loading branch information
mgduda committed Apr 16, 2024
2 parents e8d41c6 + 279df94 commit f9cfd78
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/tools/registry/gen_inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/

if(in_subpool){
fortprintf(fd, "\n");
fortprintf(fd, " allocate(recordPool)\n");
fortprintf(fd, " call mpas_pool_create_pool(recordPool)\n");
fortprintf(fd, " call mpas_pool_add_subpool(configPool, '%s', recordPool)\n", nmlrecname);
fortprintf(fd, "\n");
Expand Down Expand Up @@ -1886,7 +1885,6 @@ int parse_struct(FILE *fd, ezxml_t registry, ezxml_t superStruct, int subpool, c
fortprintf(fd, "\n");

// Setup new pool to be added into structPool
fortprintf(fd, " allocate(newSubPool)\n");
fortprintf(fd, " call mpas_pool_create_pool(newSubPool)\n");
fortprintf(fd, " call mpas_pool_add_subpool(structPool, '%s', newSubPool)\n", structnameincode);
fortprintf(fd, " call mpas_pool_add_subpool(block %% allStructs, '%s', newSubPool)\n", structname);
Expand Down

0 comments on commit f9cfd78

Please sign in to comment.