Skip to content

Commit

Permalink
destroy pointer in json_file before loading
Browse files Browse the repository at this point in the history
To prevent a memory leak if the type is used later to load another file. Fixes #561
  • Loading branch information
jacobwilliams committed May 27, 2024
1 parent 99106c0 commit 42f5649
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/json_file_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ subroutine json_file_load(me, filename, unit)
!! (if not present, a newunit
!! is used)

call me%destroy()
call me%core%load(file=filename, p=me%p, unit=unit)

end subroutine json_file_load
Expand All @@ -875,6 +876,7 @@ subroutine json_file_load_from_string(me, str)
class(json_file),intent(inout) :: me
character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from

call me%destroy()
call me%core%deserialize(me%p, str)

end subroutine json_file_load_from_string
Expand Down Expand Up @@ -1997,7 +1999,7 @@ subroutine json_file_add(me,p,destroy_original)
destroy = .true. ! default
end if

if (destroy) call me%core%destroy(me%p)
if (destroy) call me%destroy()

me%p => p

Expand Down

0 comments on commit 42f5649

Please sign in to comment.