Destroy a json_value linked-list structure.
The original FSON version of this routine was not properly freeing the memory. It was rewritten.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | variable to destroy |
||
logical(kind=LK), | intent(in), | optional | :: | destroy_next | if true, then |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
recursive subroutine json_value_destroy(json,p,destroy_next)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: p !! variable to destroy
logical(LK),intent(in),optional :: destroy_next !! if true, then `p%next`
!! is also destroyed (default is true)
logical(LK) :: des_next
type(json_value), pointer :: child
if (associated(p)) then
if (present(destroy_next)) then
des_next = destroy_next
else
des_next = .true.
end if
if (allocated(p%name)) deallocate(p%name)
call destroy_json_data(p)
if (associated(p%children)) then
do while (p%n_children > 0)
child => p%children
if (associated(child)) then
p%children => p%children%next
p%n_children = p%n_children - 1
call json%destroy(child,.false.)
else
call json%throw_exception('Error in json_value_destroy: '//&
'Malformed JSON linked list')
exit
end if
end do
nullify(p%children)
nullify(child)
end if
if (associated(p%next) .and. des_next) call json%destroy(p%next)
if (associated(p%previous)) nullify(p%previous)
if (associated(p%parent)) nullify(p%parent)
if (associated(p%tail)) nullify(p%tail)
deallocate(p)
nullify(p)
end if
end subroutine json_value_destroy