Fix bug in registry-generated code to set up derived dimensions#1458
Open
mgduda wants to merge 1 commit into
Open
Fix bug in registry-generated code to set up derived dimensions#1458mgduda wants to merge 1 commit into
mgduda wants to merge 1 commit into
Conversation
The previous commit (ae45a18) aimed to fix memory leaks that occurred while setting up derived dimensions by deallocating dimensions after they were allocated and added to the dimension pool (since the pool assigns the value of the dimension to its own internal memory, it is up to calling code to free any memory allocated for the dimension argument to mpas_pool_add_dimension). However, any later derived dimensions that depended on a dimension whose value came from a namelist or other registry definiton would generate a segmentation fault after referencing an unassociated pointer to the now deallocated dimension. For example, in the init_atmosphere core, the 'nVertLevels' dimension is set based on the namelist option 'config_nvertlevels', and the 'nVertLevelsP1' dimension is subsequently set to 'nVertLevels+1'. This commit fixes this issue by re-setting pointers to point to pool-owned memory after a dimension has been allocated, added to the dimension pool, and freed.
Contributor
Author
|
For the record, it's entirely my fault that this issue made its way into the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in registry-generated code for setting up derived dimensions.
Previous work (in PR #1451, commit ae45a18) introduced changes to eliminate memory leaks that occurred while setting up derived dimensions. The approach taken in that work involved deallocating dimensions after they were allocated and added to the dimension pool, since the pool assigns the value of the dimension to its own internal memory, and it is up to calling code to free any memory allocated for the dimension argument to
mpas_pool_add_dimension. However, as an unintended side effect, any later derived dimensions that depended on a dimension whose value came from a namelist or other registry definiton would generate a segmentation fault after referencing an unassociated pointer to the now deallocated dimension.For example, in the
init_atmospherecore, thenVertLevelsdimension is set based on the namelist optionconfig_nvertlevels, and thenVertLevelsP1dimension is subsequently set tonVertLevels+1.This PR fixes this issue by re-setting pointers to point to pool-owned memory after a dimension has been allocated, added to the dimension pool, and freed.