Skip to content

Fix mpp_gather/scatter memory leak#1892

Draft
abrooks1085 wants to merge 3 commits into
NOAA-GFDL:mainfrom
abrooks1085:fix/mpp-gather-scatter-valgrind
Draft

Fix mpp_gather/scatter memory leak#1892
abrooks1085 wants to merge 3 commits into
NOAA-GFDL:mainfrom
abrooks1085:fix/mpp-gather-scatter-valgrind

Conversation

@abrooks1085

@abrooks1085 abrooks1085 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description
This PR fixes Valgrind-reported memory errors in the MPP gather/scatter paths.

The issue was caused by passing either an unassociated pointer array or an unallocated allocatable array as an actual argument to a subroutine whose corresponding dummy argument is an assumed-shape intent(in) array. In these cases, the call is invalid because the assumed-shape dummy requires a valid array descriptor from the actual argument. Even when the data is only logically used on the root rank, forwarding an invalid array argument on another rank can still expose undefined descriptor state and trigger memory diagnostics.

This PR updates the affected gather/scatter wrapper paths so that all ranks pass valid array arguments into the lower-level routines. For ranks that do not logically contribute or consume the full root-side buffer, a valid temporary array/view is used instead of forwarding an unassociated pointer or unallocated allocatable.

Fixes #1890

How Has This Been Tested?

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included
  • make distcheck passes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory errors detected by memcheck (valgrind)

1 participant