Skip to content

Commit

Permalink
Merge pull request #1566 from ExtremeFLOW/fix/dangling_ptrs_case
Browse files Browse the repository at this point in the history
Fix dangling pointers from Case and scratch init
  • Loading branch information
njansson authored Oct 30, 2024
2 parents e44ebab + 02d5077 commit 512ec9d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/case.f90
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ subroutine case_free(this)

call this%msh%free()

call this%f_out%free()

call this%output_controller%free()

end subroutine case_free
Expand Down
8 changes: 6 additions & 2 deletions src/field/scratch_registry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module scratch_registry
!> the size the fields array is increased by upon reallocation
integer, private :: expansion_size
!> Dofmap
type(dofmap_t), pointer :: dof
type(dofmap_t), pointer :: dof => null()
contains
procedure, private, pass(this) :: expand
!> destructor
Expand Down Expand Up @@ -94,6 +94,8 @@ type(scratch_registry_t) function init(dof, size, expansion_size) result(this)
integer, optional, intent(in) :: expansion_size
integer :: i

call this%free()

this%dof => dof

if (present(size)) then
Expand Down Expand Up @@ -133,7 +135,9 @@ subroutine scratch_registry_free(this)
deallocate(this%inuse)
end if

nullify(this%dof)
if (associated(this%dof)) then
nullify(this%dof)
end if

end subroutine scratch_registry_free

Expand Down
2 changes: 1 addition & 1 deletion src/fluid/fluid_pnpn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ subroutine fluid_pnpn_init(this, msh, lx, params, user, time_scheme)
type(mesh_t), target, intent(inout) :: msh
integer, intent(inout) :: lx
type(json_file), target, intent(inout) :: params
type(user_t), intent(in) :: user
type(user_t), target, intent(in) :: user
type(time_scheme_controller_t), target, intent(in) :: time_scheme
character(len=15), parameter :: scheme = 'Modular (Pn/Pn)'

Expand Down
2 changes: 1 addition & 1 deletion src/fluid/fluid_scheme.f90
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ subroutine fluid_scheme_init_intrf(this, msh, lx, params, user, &
type(mesh_t), target, intent(inout) :: msh
integer, intent(inout) :: lx
type(json_file), target, intent(inout) :: params
type(user_t), intent(in) :: user
type(user_t), target, intent(in) :: user
type(time_scheme_controller_t), target, intent(in) :: time_scheme
end subroutine fluid_scheme_init_intrf
end interface
Expand Down
9 changes: 9 additions & 0 deletions src/io/fluid_output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module fluid_output
type(field_list_t) :: fluid
contains
procedure, pass(this) :: sample => fluid_output_sample
procedure, pass(this) :: free => fluid_output_free
end type fluid_output_t

interface fluid_output_t
Expand Down Expand Up @@ -93,6 +94,14 @@ function fluid_output_init(precision, fluid, scalar, name, path) result(this)

end function fluid_output_init

!> Destroy a fluid output list
subroutine fluid_output_free(this)
class(fluid_output_t), intent(inout) :: this

call this%fluid%free()

end subroutine fluid_output_free

!> Sample a fluid solution at time @a t
subroutine fluid_output_sample(this, t)
class(fluid_output_t), intent(inout) :: this
Expand Down
3 changes: 2 additions & 1 deletion src/neko.f90
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,13 @@ subroutine neko_finalize(C)
call neko_rt_stats%report()
call neko_rt_stats%free()

call neko_scratch_registry%free()

if (present(C)) then
call case_free(C)
end if

call neko_field_registry%free()
call neko_scratch_registry%free()
call device_finalize
call neko_mpi_types_free
call comm_free
Expand Down

0 comments on commit 512ec9d

Please sign in to comment.