about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-01 20:54:42 +0200
committerbptato <nincsnevem662@gmail.com>2024-10-01 20:54:42 +0200
commitee113a5643ed32b7f6ed2522aed92ac700021097 (patch)
tree3b58640d759a514b9172fc5b7fa5c281bf94371b
parent7277dd7c357cfa10838b1e694aaf32128082d088 (diff)
downloadchawan-ee113a5643ed32b7f6ed2522aed92ac700021097.tar.gz
loader: add missing nil check in openCachedItem
also, erase cacheRef when it couldn't be opened
-rw-r--r--src/loader/loader.nim5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 28119f0e..0d6c655a 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -241,6 +241,9 @@ proc openCachedItem(client: ClientData; id: int): (PosixStream, int) =
   if n != -1:
     let item = client.cacheMap[n]
     let ps = newPosixStream(client.cacheMap[n].path, O_RDONLY, 0)
+    if ps == nil:
+      client.cacheMap.del(n)
+      return (nil, -1)
     assert item.offset != -1
     ps.seek(item.offset)
     return (ps, n)
@@ -409,7 +412,7 @@ proc finishParse(handle: InputHandle) =
           handle.parser = nil
           break
       handle.cacheRef.offset = off
-      handle.cacheRef = nil
+    handle.cacheRef = nil
   if handle.parser != nil:
     discard handle.parseHeaders(nil)