aboutsummaryrefslogtreecommitdiffstats
path: root/src/loader
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-08 18:17:49 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-08 18:17:49 +0100
commite5a61582fb5eddaefb50840c16685327716d854c (patch)
tree96e496d8baa92508e4210b488c1612ece6db8d94 /src/loader
parent501eba69140a327913cbbc486238a38feaf0a6f3 (diff)
downloadchawan-e5a61582fb5eddaefb50840c16685327716d854c.tar.gz
loader: fix (another) double-close bug
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/loader.nim12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 18cd7767..3b4e016f 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -339,10 +339,14 @@ proc runFileLoader*(fd: cint, config: LoaderConfig) =
unregWrite.add(handle)
#TODO TODO TODO what to do about sostream
for handle in unregWrite:
- ctx.selector.unregister(handle.fd)
- ctx.handleMap.del(handle.fd)
- handle.ostream.close()
- handle.ostream = nil
+ if handle.ostream != nil:
+ # if the previous loop adds its handle to this one, it is possible that
+ # we try to unregister the same handle twice
+ #TODO this is kind of a mess
+ ctx.selector.unregister(handle.fd)
+ ctx.handleMap.del(handle.fd)
+ handle.ostream.close()
+ handle.ostream = nil
if handle.istream != nil:
ctx.handleMap.del(handle.istream.fd)
ctx.selector.unregister(handle.istream.fd)