Skip to content

Add if(allocated) checks to avoid segfaults#82

Merged
jkbk2004 merged 2 commits into
NOAA-PSL:masterfrom
NickSzapiro-NOAA:fix_alloc_wts
May 1, 2025
Merged

Add if(allocated) checks to avoid segfaults#82
jkbk2004 merged 2 commits into
NOAA-PSL:masterfrom
NickSzapiro-NOAA:fix_alloc_wts

Conversation

@NickSzapiro-NOAA
Copy link
Copy Markdown
Contributor

Code currently fills sppt_wts and skeb_wts whether or not associated with a target or allocated in MOM6. This leads to a segmentation fault in a UFS regression test (see ufs-community/ufs-weather-model#2711)

Protect by checking whether allocated first

…physics_ocn in stochastic_physics.F90

Fix segfault from attempt to use pointer SKEB_WTS when it is not associated with a target
@pjpegion
Copy link
Copy Markdown
Collaborator

I recommend splitting the if (pert_epbl .OR. do_ocnsppt) then block to be:

allocate(tmp_wts(gis_stochy_ocn%nx, gis_stochy_ocn%ny))
if (pert_epbl ) then
call get_random_pattern_scalar(rpattern_epbl1, nepbl, gis_stochy_ocn, tmp_wts)
t_rp1(:,:) = 2.0 / (1.0 + exp(-1 * tmp_wts))
call get_random_pattern_scalar(rpattern_epbl2, nepbl, gis_stochy_ocn, tmp_wts)
t_rp2(:,:) = 2.0 / (1.0 + exp(-1 * tmp_wts))
endif
if (do_ocnsppt) then
call get_random_pattern_scalar(rpattern_ocnsppt, nocnsppt, gis_stochy_ocn, tmp_wts)
sppt_wts = 2.0 / (1.0 + exp(-1 * tmp_wts))
else
deallocate(tmp_wts)

@NickSzapiro-NOAA
Copy link
Copy Markdown
Contributor Author

@pjpegion Is this what you mean, to split the options?

Copy link
Copy Markdown
Collaborator

@pjpegion pjpegion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good

@jkbk2004 jkbk2004 merged commit b5cec8b into NOAA-PSL:master May 1, 2025
jkbk2004 added a commit that referenced this pull request May 1, 2025
(PLATFORM-1077) Adding CI/CD capabilities and Unit Tests + Add if(allocated) checks to avoid segfaults #82
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.

3 participants