From fa52280fae20495970fff83f80faa3f02dd1e025 Mon Sep 17 00:00:00 2001 From: James Kermode Date: Wed, 20 Sep 2023 13:39:25 +0100 Subject: [PATCH] Avoid double free seg faults --- src/fileio.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/fileio.jl b/src/fileio.jl index 694ce7a..76e1f6c 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -203,16 +203,19 @@ function read_frame_dicts(fp::Ptr{Cvoid}; verbose=false) nat = Ref{Cint}(0) info = Ref{Ptr{DictEntry}}() arrays = Ref{Ptr{DictEntry}}() - eof = false + failed = false try res = ccall((:extxyz_read_ll, libextxyz), Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Ref{Cint}, Ptr{Ptr{DictEntry}}, Ptr{Ptr{DictEntry}}), _kv_grammar[], fp, nat, info, arrays) if res != 1 - eof = true + failed = true throw(EOFError()) end - (nat[] == 0) && error("ExtXYZ frame contains zero atoms. Behaviour is undefined!") + if nat[] == 0 + failed = true + error("ExtXYZ frame contains zero atoms. Behaviour is undefined!") + end if verbose cprint_dict(info[]) cprint_dict(arrays[]) @@ -225,7 +228,7 @@ function read_frame_dicts(fp::Ptr{Cvoid}; verbose=false) return nat[], jinfo, jarrays finally - if !eof + if !failed cfree_dict(info[]) cfree_dict(arrays[]) end