Skip to content

Commit 19e6f16

Browse files
Merge pull request #493 from jacobwilliams/488-empty-array-leak
Fix for a memory leak when parsing an empty array
2 parents ddd240b + a848095 commit 19e6f16

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/json_value_module.F90

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10127,7 +10127,7 @@ recursive subroutine parse_value(json, unit, str, value)
1012710127

1012810128
! pop the next non whitespace character off the file
1012910129
call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., &
10130-
skip_comments=json%allow_comments, popped=c)
10130+
skip_comments=json%allow_comments, popped=c)
1013110131

1013210132
if (eof) then
1013310133
return
@@ -10151,7 +10151,10 @@ recursive subroutine parse_value(json, unit, str, value)
1015110151

1015210152
! end an empty array
1015310153
call json%push_char(c)
10154-
nullify(value)
10154+
if (associated(value)) then
10155+
deallocate(value)
10156+
nullify(value)
10157+
end if
1015510158

1015610159
case (quotation_mark)
1015710160

@@ -10990,17 +10993,17 @@ recursive subroutine parse_array(json, unit, str, array)
1099010993
exit
1099110994
end if
1099210995

10993-
! parse value will disassociate an empty array value
10996+
! parse value will deallocate an empty array value
1099410997
if (associated(element)) call json%add(array, element)
1099510998

1099610999
! popped the next character
1099711000
call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., &
10998-
skip_comments=json%allow_comments, popped=c)
11001+
skip_comments=json%allow_comments, popped=c)
1099911002

1100011003
if (eof) then
1100111004
! The file ended before array was finished:
1100211005
call json%throw_exception('Error in parse_array: '//&
11003-
'End of file encountered when parsing an array.')
11006+
'End of file encountered when parsing an array.')
1100411007
exit
1100511008
else if (delimiter == c) then
1100611009
! parse the next element

0 commit comments

Comments
 (0)