Skip to content

Commit 83219b6

Browse files
committed
fixing some memory issues in the unit tests
See #494
1 parent f5078a4 commit 83219b6

File tree

8 files changed

+19
-7
lines changed

8 files changed

+19
-7
lines changed

src/tests/jf_test_02.F90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ subroutine test_2(error_cnt)
335335
call json%print_error_message(error_unit)
336336
error_cnt = error_cnt + 1
337337
end if
338+
call json%destroy(p_clone)
339+
if (json%failed()) then
340+
call json%print_error_message(error_unit)
341+
error_cnt = error_cnt + 1
342+
end if
338343

339344
write(error_unit,'(A)') ''
340345

src/tests/jf_test_10.F90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ subroutine test_10(error_cnt)
321321
write(error_unit,'(A)') 'json_create_real ...'; call json%destroy(p); call json%create_real (p,9.0_wp,'foo')
322322
write(error_unit,'(A)') 'json_create_string ...'; call json%destroy(p); call json%create_string (p,'foo','bar')
323323
write(error_unit,'(A)') 'json_create_null ...'; call json%destroy(p); call json%create_null (p,'foo')
324-
write(error_unit,'(A)') 'json_create_object ...'; call json%destroy(p); call json%create_object (p,'foo')
324+
write(error_unit,'(A)') 'json_create_object ...'; call json%destroy(p); call json%create_object (p,'foo')
325+
call json%destroy(p)
325326
if (json%failed()) then
326327
call json%print_error_message(error_unit)
327328
error_cnt = error_cnt + 1

src/tests/jf_test_12.F90

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ module jf_test_12_mod
1414
private
1515
public :: test_12
1616

17-
character(len=*),parameter :: dir = '../files/' !! Path to write JSON file to
18-
character(len=*),parameter :: file = 'test12.json' !! Filename to write
19-
real(wp), parameter :: TOL = 100*epsilon(1.0_wp) !! Tolerance for real comparisons
20-
2117
contains
2218

2319
subroutine test_12(error_cnt)
@@ -27,6 +23,8 @@ subroutine test_12(error_cnt)
2723
integer,intent(out) :: error_cnt !! report number of errors to caller
2824

2925
integer(IK),parameter :: imx = 5, jmx = 3, kmx = 4 !! dimensions for raw work array of primitive type
26+
character(len=*),parameter :: file = '../files/test12.json' !! Filename to write
27+
real(wp), parameter :: TOL = 100*epsilon(1.0_wp) !! Tolerance for real comparisons
3028

3129
type(json_core) :: json !! factory for manipulating `json_value` pointers
3230
integer(IK),dimension(3) :: shape !! shape of work array
@@ -58,7 +56,7 @@ subroutine test_12(error_cnt)
5856
raw_array(i,j,k) = i + (j-1_IK)*imx + (k-1_IK)*imx*jmx
5957
end forall
6058

61-
call json%create_object(root,dir//file)
59+
call json%create_object(root,file)
6260
call check_errors()
6361

6462
call json%create_object(meta_array,'array data')
@@ -172,7 +170,7 @@ subroutine test_12(error_cnt)
172170
! call my_file%get(tmp_json_ptr)
173171
! call check_file_errors(associated(tmp_json_ptr,root))
174172

175-
open(file=dir//file,newunit=lun,form='formatted',action='write')
173+
open(file=file,newunit=lun,form='formatted',action='write')
176174
call my_file%print(lun)
177175
call check_file_errors()
178176
close(lun)

src/tests/jf_test_14.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ subroutine test_14(error_cnt)
113113
error_cnt = error_cnt + 1
114114
end if
115115

116+
if (allocated(new_name)) deallocate(new_name)
117+
116118
end subroutine test_14
117119

118120
subroutine rename(json,p,finished) !! change all "name" variable values to "Fred"

src/tests/jf_test_20.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ subroutine test_20(error_cnt)
183183

184184
! cleanup:
185185
call json%destroy(p)
186+
call json%destroy(root)
186187

187188
! now, just a test of the edge case:
188189
! (where p doesn't have a parent)

src/tests/jf_test_34.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ subroutine test_34(error_cnt)
141141
call json%initialize(trailing_spaces_significant=.true.)
142142
call json%create_integer(p,1_IK,CK_'a')
143143
call json%rename(p,CK_'b ')
144+
call json%destroy(p)
144145

145146
end subroutine test_34
146147

src/tests/jf_test_44.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ subroutine test_44(error_cnt)
5252
error_cnt = error_cnt + 1
5353
end if
5454

55+
call json%destroy(p)
56+
5557
if (error_cnt==0) then
5658
write(error_unit,'(A)') 'Success!'
5759
else

src/tests/jf_test_47.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ subroutine test_47(error_cnt)
117117

118118
end if
119119

120+
call json%destroy(inp)
121+
120122
write(error_unit,'(A)') ''
121123
if (error_cnt==0) then
122124
write(error_unit,'(A)') 'Success!'

0 commit comments

Comments
 (0)