Skip to content

Commit 7afba2b

Browse files
committed
remove f = json_file() calls from unit tests
These are causing memory leaks with gfortran See #563
1 parent c41a0c0 commit 7afba2b

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

src/tests/jf_test_15.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ subroutine test_15(error_cnt)
216216

217217
!****************************************
218218

219-
file1 = json_file(p2,json) !constructor
219+
!file1 = json_file(p2,json) ! memory leak with gfortran?
220+
call file1%initialize(json)
221+
call file1%add(p2); nullify(p2)
220222
call file1%destroy(destroy_core=.true.)
221223

222224
!****************************************

src/tests/jf_test_25.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ subroutine test_25(error_cnt)
108108
#endif
109109

110110
! test json_file interface
111-
f = json_file(p)
111+
!f = json_file(p) ! memory leak in gfortran?
112+
call f%initialize()
113+
call f%add(p)
112114
nullify(p) ! data is now in f
113115
call f%get('str_array', vec, ilen, found)
114116
if (.not. found) then

src/tests/jf_test_27.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ subroutine test_27(error_cnt)
6060
call json%print(p,int(output_unit,IK))
6161

6262
! test json_file interface
63-
f = json_file(p)
63+
!f = json_file(p) ! memory leak in gfortran?
64+
call f%initialize()
65+
call f%add(p)
6466
nullify(p) ! data is now in f
6567
call f%initialize(compress_vectors=.true.)
6668
call f%print()

src/tests/jf_test_37.F90

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,34 @@ subroutine test_37(error_cnt)
3939
call json%initialize(no_whitespace=.true.)
4040

4141
call json%deserialize(p, CK_'{"a": ["1", "2", "3"]}')
42-
f = json_file(p,no_whitespace=.true.)
42+
!f = json_file(p,no_whitespace=.true.) ! memory leak in gfortran?
43+
call f%initialize(no_whitespace=.true.)
44+
call f%add(p)
4345
call f%print(int(error_unit,IK))
4446
write(error_unit,'(A)') ''
4547
call check_for_error()
4648
call f%destroy()
4749

4850
call json%deserialize(p, CK_'{"b": ["4", "5", "6"]}')
49-
f = json_file(p,json)
51+
!f = json_file(p,json) ! memory leak in gfortran?
52+
call f%initialize(json)
53+
call f%add(p)
5054
call f%print(int(error_unit,IK))
5155
write(error_unit,'(A)') ''
5256
call check_for_error()
5357
call f%destroy()
5458

55-
f = json_file(CK_'{"x": [1,2,3]}',no_whitespace=.true.)
59+
!f = json_file(CK_'{"x": [1,2,3]}',no_whitespace=.true.) ! memory leak in gfortran?
60+
call f%initialize(no_whitespace=.true.)
61+
call f%deserialize(CK_'{"x": [1,2,3]}')
5662
call f%print(int(error_unit,IK))
5763
write(error_unit,'(A)') ''
5864
call check_for_error()
5965
call f%destroy()
6066

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

7179
call json%deserialize(p, CDK_'{"a": ["1", "2", "3"]}')
72-
f = json_file(p,no_whitespace=.true.)
80+
!f = json_file(p,no_whitespace=.true.) ! memory leak in gfortran?
81+
call f%initialize(no_whitespace=.true.)
82+
call f%add(p)
7383
call f%print(int(error_unit,IK))
7484
write(error_unit,'(A)') ''
7585
call check_for_error()
7686
call f%destroy()
7787

7888
call json%deserialize(p, CDK_'{"b": ["4", "5", "6"]}')
79-
f = json_file(p,json)
89+
!f = json_file(p,json) ! memory leak in gfortran?
90+
call f%initialize(json)
91+
call f%add(p)
8092
call f%print(int(error_unit,IK))
8193
write(error_unit,'(A)') ''
8294
call check_for_error()
8395
call f%destroy()
8496

85-
f = json_file(CDK_'{"x": [1,2,3]}',no_whitespace=.true.)
97+
!f = json_file(CDK_'{"x": [1,2,3]}',no_whitespace=.true.) ! memory leak in gfortran?
98+
call f%initialize(no_whitespace=.true.)
99+
call f%deserialize(CDK_'{"x": [1,2,3]}')
86100
call f%print(int(error_unit,IK))
87101
write(error_unit,'(A)') ''
88102
call check_for_error()
89103
call f%destroy()
90104

91-
f = json_file(CDK_'{"y": [4,5,6]}',json)
105+
!f = json_file(CDK_'{"y": [4,5,6]}',json) ! memory leak in gfortran?
106+
call f%initialize(json)
107+
call f%deserialize(CDK_'{"y": [4,5,6]}')
92108
call f%print(int(error_unit,IK))
93109
write(error_unit,'(A)') ''
94110
call check_for_error()

src/tests/jf_test_39.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ subroutine test_39(error_cnt)
4444

4545
do i = 1, size(tests)
4646

47-
json = json_file(trim(tests(i)),verbose=.true.,stop_on_error=.true.)
47+
!json = json_file(trim(tests(i)),verbose=.true.,stop_on_error=.true.) ! memory leak in gfortran?
48+
call json%initialize(verbose=.true.,stop_on_error=.true.)
49+
call json%deserialize(trim(tests(i)))
4850
call json%print(int(error_unit,IK))
4951
write(error_unit,'(A)') ''
5052
if (json%failed()) then

src/tests/jf_test_41.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ subroutine test_41(error_cnt)
5757
write(error_unit,'(A)') ''
5858
write(error_unit,'(A)') 'copying to json_file...'
5959

60-
f = json_file(p)
60+
!f = json_file(p) ! memory leak in gfortran?
61+
call f%initialize()
62+
call f%add(p)
6163

6264
call f2%add(p2)
6365
nullify(p2) ! data is now in f

src/tests/jf_test_46.F90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ subroutine test_46(error_cnt)
166166
! now, json_file routines:
167167
!---------------------------------
168168

169-
json_f = json_file(str)
169+
!json_f = json_file(str) ! memory leak in gfortran?
170+
call json_f%deserialize(str)
170171

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

0 commit comments

Comments
 (0)