Skip to content

Commit

Permalink
remove f = json_file() calls from unit tests
Browse files Browse the repository at this point in the history
These are causing memory leaks with gfortran
See #563
  • Loading branch information
jacobwilliams committed Jun 1, 2024
1 parent c41a0c0 commit 7afba2b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/tests/jf_test_15.F90
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ subroutine test_15(error_cnt)

!****************************************

file1 = json_file(p2,json) !constructor
!file1 = json_file(p2,json) ! memory leak with gfortran?
call file1%initialize(json)
call file1%add(p2); nullify(p2)
call file1%destroy(destroy_core=.true.)

!****************************************
Expand Down
4 changes: 3 additions & 1 deletion src/tests/jf_test_25.F90
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ subroutine test_25(error_cnt)
#endif

! test json_file interface
f = json_file(p)
!f = json_file(p) ! memory leak in gfortran?
call f%initialize()
call f%add(p)
nullify(p) ! data is now in f
call f%get('str_array', vec, ilen, found)
if (.not. found) then
Expand Down
4 changes: 3 additions & 1 deletion src/tests/jf_test_27.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ subroutine test_27(error_cnt)
call json%print(p,int(output_unit,IK))

! test json_file interface
f = json_file(p)
!f = json_file(p) ! memory leak in gfortran?
call f%initialize()
call f%add(p)
nullify(p) ! data is now in f
call f%initialize(compress_vectors=.true.)
call f%print()
Expand Down
32 changes: 24 additions & 8 deletions src/tests/jf_test_37.F90
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,34 @@ subroutine test_37(error_cnt)
call json%initialize(no_whitespace=.true.)

call json%deserialize(p, CK_'{"a": ["1", "2", "3"]}')
f = json_file(p,no_whitespace=.true.)
!f = json_file(p,no_whitespace=.true.) ! memory leak in gfortran?
call f%initialize(no_whitespace=.true.)
call f%add(p)
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
call f%destroy()

call json%deserialize(p, CK_'{"b": ["4", "5", "6"]}')
f = json_file(p,json)
!f = json_file(p,json) ! memory leak in gfortran?
call f%initialize(json)
call f%add(p)
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
call f%destroy()

f = json_file(CK_'{"x": [1,2,3]}',no_whitespace=.true.)
!f = json_file(CK_'{"x": [1,2,3]}',no_whitespace=.true.) ! memory leak in gfortran?
call f%initialize(no_whitespace=.true.)
call f%deserialize(CK_'{"x": [1,2,3]}')
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
call f%destroy()

f = json_file(CK_'{"y": [4,5,6]}',json)
!f = json_file(CK_'{"y": [4,5,6]}',json) ! memory leak in gfortran?
call f%initialize(json)
call f%deserialize(CK_'{"y": [4,5,6]}')
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
Expand All @@ -69,26 +77,34 @@ subroutine test_37(error_cnt)
! also test default character kind when unicode is enabled:

call json%deserialize(p, CDK_'{"a": ["1", "2", "3"]}')
f = json_file(p,no_whitespace=.true.)
!f = json_file(p,no_whitespace=.true.) ! memory leak in gfortran?
call f%initialize(no_whitespace=.true.)
call f%add(p)
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
call f%destroy()

call json%deserialize(p, CDK_'{"b": ["4", "5", "6"]}')
f = json_file(p,json)
!f = json_file(p,json) ! memory leak in gfortran?
call f%initialize(json)
call f%add(p)
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
call f%destroy()

f = json_file(CDK_'{"x": [1,2,3]}',no_whitespace=.true.)
!f = json_file(CDK_'{"x": [1,2,3]}',no_whitespace=.true.) ! memory leak in gfortran?
call f%initialize(no_whitespace=.true.)
call f%deserialize(CDK_'{"x": [1,2,3]}')
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
call f%destroy()

f = json_file(CDK_'{"y": [4,5,6]}',json)
!f = json_file(CDK_'{"y": [4,5,6]}',json) ! memory leak in gfortran?
call f%initialize(json)
call f%deserialize(CDK_'{"y": [4,5,6]}')
call f%print(int(error_unit,IK))
write(error_unit,'(A)') ''
call check_for_error()
Expand Down
4 changes: 3 additions & 1 deletion src/tests/jf_test_39.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ subroutine test_39(error_cnt)

do i = 1, size(tests)

json = json_file(trim(tests(i)),verbose=.true.,stop_on_error=.true.)
!json = json_file(trim(tests(i)),verbose=.true.,stop_on_error=.true.) ! memory leak in gfortran?
call json%initialize(verbose=.true.,stop_on_error=.true.)
call json%deserialize(trim(tests(i)))
call json%print(int(error_unit,IK))
write(error_unit,'(A)') ''
if (json%failed()) then
Expand Down
4 changes: 3 additions & 1 deletion src/tests/jf_test_41.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ subroutine test_41(error_cnt)
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'copying to json_file...'

f = json_file(p)
!f = json_file(p) ! memory leak in gfortran?
call f%initialize()
call f%add(p)

call f2%add(p2)
nullify(p2) ! data is now in f
Expand Down
3 changes: 2 additions & 1 deletion src/tests/jf_test_46.F90
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ subroutine test_46(error_cnt)
! now, json_file routines:
!---------------------------------

json_f = json_file(str)
!json_f = json_file(str) ! memory leak in gfortran?
call json_f%deserialize(str)

! unicode:
call json_f%get(CK_'not_there', ival, found, default=99_IK)
Expand Down

0 comments on commit 7afba2b

Please sign in to comment.