Skip to content

Commit

Permalink
Do not close nil stream when it failed to open (#87)
Browse files Browse the repository at this point in the history
When stream fails to open during loading of TOML file, `stream` remains
set to `nil`. The `finally` block then triggers SIGSEGV when it tries
to close the stream that was never fully opened. Only install the
`finally` block once `stream` was initialized to fix this.
  • Loading branch information
etan-status authored Jun 13, 2024
1 parent abcaafe commit cb1fc73
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions toml_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,14 @@ template tomlLoadImpl*(filename: string,
RecordType: distinct type,
key: string, tomlCase: TomlCase,
params: varargs[untyped]): auto =

mixin init, ReaderType, readValue
var stream: InputStream
when nimvm:
let input = staticRead(filename)
stream = VMInputStream(pos: 0, data: toVMString(input))
else:
stream = memFileInput(filename)
try:
when nimvm:
let input = staticRead(filename)
stream = VMInputStream(pos: 0, data: toVMString(input))
else:
stream = memFileInput(filename)
var reader = unpackArgs(init, [TomlReader, stream, params])
when RecordType is (seq or array) and uTypeIsRecord(RecordType):
reader.readTableArray(RecordType, key, tomlCase)
Expand Down

0 comments on commit cb1fc73

Please sign in to comment.