Skip to content

Commit

Permalink
fix memory leak in NUOPC State_getImport method
Browse files Browse the repository at this point in the history
  • Loading branch information
alperaltuntas committed Sep 23, 2024
1 parent 37411fb commit c346f40
Showing 1 changed file with 2 additions and 28 deletions.
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

0 comments on commit c346f40

Please sign in to comment.