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

fix memory leak in NUOPC State_getImport method #303

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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
30 changes: 2 additions & 28 deletions config_src/drivers/nuopc_cap/mom_cap_methods.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module MOM_cap_methods
!> Get field pointer
interface State_GetFldPtr
module procedure State_GetFldPtr_1d
module procedure State_GetFldPtr_1d_from_2d
module procedure State_GetFldPtr_2d
end interface

Expand Down Expand Up @@ -850,32 +849,6 @@ subroutine State_GetFldPtr_1d(State, fldname, fldptr, rc)

end subroutine State_GetFldPtr_1d

!> Get specific 1D field pointer from 2D field
subroutine State_GetFldPtr_1d_from_2d(State, fldname, esmf_ind, fldptr, rc)
type(ESMF_State) , intent(in) :: State !< ESMF state
character(len=*) , intent(in) :: fldname !< Field name
real(ESMF_KIND_R8), pointer :: fldptr(:)!< Pointer to the 1D field
integer, intent(in) :: esmf_ind !< Index into 2D ESMF array
integer, optional , intent(out) :: rc !< Return code

! local variables
real(ESMF_KIND_R8), pointer :: fldptr2d(:,:)!< Pointer to the 1D field
type(ESMF_Field) :: lfield
integer :: lrc
character(len=*),parameter :: subname='(MOM_cap:State_GetFldPtr)'

call ESMF_StateGet(State, itemName=trim(fldname), field=lfield, rc=lrc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldGet(lfield, farrayPtr=fldptr2d, rc=lrc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (.not. associated(fldptr)) allocate(fldptr(size(fldptr2d,2)))
fldptr = fldptr2d(esmf_ind, :)

if (present(rc)) rc = lrc

end subroutine State_GetFldPtr_1d_from_2d

!> Get field pointer 2D
subroutine State_GetFldPtr_2d(State, fldname, fldptr, rc)
type(ESMF_State) , intent(in) :: State !< ESMF state
Expand Down Expand Up @@ -940,7 +913,8 @@ subroutine State_GetImport_2d(state, fldname, isc, iec, jsc, jec, output, do_sum

! get field pointer
if (present(esmf_ind)) then
call state_getfldptr(state, trim(fldname), esmf_ind, dataptr1d, rc)
call state_getfldptr(state, trim(fldname), dataptr2d, rc)
dataptr1d => dataptr2d(esmf_ind,:)
else
call state_getfldptr(state, trim(fldname), dataptr1d, rc)
endif
Expand Down
Loading