Skip to content

Commit ea659af

Browse files
committed
fixed a memory leak when parsing an invalid JSON
See #494
1 parent 83219b6 commit ea659af

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/json_value_module.F90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10895,7 +10895,7 @@ recursive subroutine parse_object(json, unit, str, parent)
1089510895
skip_comments=json%allow_comments, popped=c)
1089610896
if (eof) then
1089710897
call json%throw_exception('Error in parse_object:'//&
10898-
' Unexpected end of file while parsing start of object.')
10898+
' Unexpected end of file while parsing start of object.')
1089910899
return
1090010900
else if (end_object == c) then
1090110901
! end of an empty object
@@ -10922,8 +10922,9 @@ recursive subroutine parse_object(json, unit, str, parent)
1092210922
call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., &
1092310923
skip_comments=json%allow_comments, popped=c)
1092410924
if (eof) then
10925+
call json%destroy(pair)
1092510926
call json%throw_exception('Error in parse_object:'//&
10926-
' Unexpected end of file while parsing object member.')
10927+
' Unexpected end of file while parsing object member.')
1092710928
return
1092810929
else if (colon_char == c) then
1092910930
! parse the value
@@ -10935,6 +10936,7 @@ recursive subroutine parse_object(json, unit, str, parent)
1093510936
call json%add(parent, pair)
1093610937
end if
1093710938
else
10939+
call json%destroy(pair)
1093810940
call json%throw_exception('Error in parse_object:'//&
1093910941
' Expecting : and then a value: '//c)
1094010942
return
@@ -10945,7 +10947,7 @@ recursive subroutine parse_object(json, unit, str, parent)
1094510947
skip_comments=json%allow_comments, popped=c)
1094610948
if (eof) then
1094710949
call json%throw_exception('Error in parse_object: '//&
10948-
'End of file encountered when parsing an object')
10950+
'End of file encountered when parsing an object')
1094910951
return
1095010952
else if (delimiter == c) then
1095110953
! read the next member

0 commit comments

Comments
 (0)