Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra safe-guard to pointer allocation when a pointer is passed as an argument #1107

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions amip_interp/amip_interp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ module amip_interp_mod
type amip_interp_type
private
type (horiz_interp_type) :: Hintrp, Hintrp2 ! add by JHC
real, pointer :: data1(:,:) =>NULL(), &
data2(:,:) =>NULL()
real, allocatable :: data1(:,:), data2(:,:)
type (date_type) :: Date1, Date2
logical :: use_climo, use_annual
logical :: I_am_initialized=.false.
Expand Down Expand Up @@ -1003,8 +1002,8 @@ end subroutine amip_interp_init
!! when calling get_amip_sst and get_amip_ice.
subroutine amip_interp_del (Interp)
type (amip_interp_type), intent(inout) :: Interp
if(associated(Interp%data1)) deallocate(Interp%data1)
if(associated(Interp%data2)) deallocate(Interp%data2)
if(allocated(Interp%data1)) deallocate(Interp%data1)
if(allocated(Interp%data2)) deallocate(Interp%data2)
if(allocated(lon_bnd)) deallocate(lon_bnd)
if(allocated(lat_bnd)) deallocate(lat_bnd)
call horiz_interp_del ( Interp%Hintrp )
Expand Down Expand Up @@ -1536,8 +1535,9 @@ subroutine amip_interp_type_eq(amip_interp_out, amip_interp_in)
endif

amip_interp_out%Hintrp = amip_interp_in%Hintrp
amip_interp_out%data1 => amip_interp_in%data1
amip_interp_out%data2 => amip_interp_in%data2
amip_interp_out%Hintrp2 = amip_interp_in%Hintrp2 !< missing assignment statement; added by GPP
amip_interp_out%data1 = amip_interp_in%data1
amip_interp_out%data2 = amip_interp_in%data2
amip_interp_out%Date1 = amip_interp_in%Date1
amip_interp_out%Date2 = amip_interp_in%Date2
amip_interp_out%Date1 = amip_interp_in%Date1
Expand Down
4 changes: 4 additions & 0 deletions coupler/coupler_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3191,6 +3191,7 @@ subroutine CT_register_restarts_2d(var, bc_rest_files, num_rest_files, mpp_domai

if (num_rest_files == 0) return

if (associated(bc_rest_files)) deallocate(bc_rest_files) !< Add extra safe-guard before allocation
allocate(bc_rest_files(num_rest_files))

!< Open the files
Expand Down Expand Up @@ -3394,6 +3395,7 @@ subroutine CT_register_restarts_3d(var, bc_rest_files, num_rest_files, mpp_domai

if (num_rest_files == 0) return

if (associated(bc_rest_files)) deallocate(bc_rest_files) !< Add extra safe-guard before allocation
allocate(bc_rest_files(num_rest_files))

!< Open the files
Expand Down Expand Up @@ -3776,6 +3778,7 @@ subroutine mpp_io_CT_register_restarts_2d(var, bc_rest_files, num_rest_files, mp
if (num_rest_files == 0) return

! Register the fields with the restart files
if (associated(bc_rest_files)) deallocate(bc_rest_files) !< Add extra safe-guard before allocation
allocate(bc_rest_files(num_rest_files))
do n = 1, var%num_bcs
if (var%bc(n)%num_fields <= 0) cycle
Expand Down Expand Up @@ -3866,6 +3869,7 @@ subroutine mpp_io_CT_register_restarts_3d(var, bc_rest_files, num_rest_files, mp
if (num_rest_files == 0) return

! Register the fields with the restart files
if (associated(bc_rest_files)) deallocate(bc_rest_files) !< Add extra safe-guard before allocation
allocate(bc_rest_files(num_rest_files))
do n = 1, var%num_bcs
if (var%bc(n)%num_fields <= 0) cycle
Expand Down