about summary refs log tree commit diff stats
path: root/src/loader
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-20 15:28:35 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-20 15:31:55 +0200
commit7cafa1f5e0f1e83ec5064764284433d64e94cc9f (patch)
tree97e10041df5a6d58a6a7f77538b81d3d1c8a3729 /src/loader
parent4183fbf5bc53e4208df443f343f97ab466384e21 (diff)
downloadchawan-7cafa1f5e0f1e83ec5064764284433d64e94cc9f.tar.gz
loader: copy cached items on buffer cloning
This fixes a bug where cloning buffers with images would crash the
browser.
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/loader.nim13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index f773936f..955529d9 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -524,14 +524,22 @@ proc addClient(ctx: LoaderContext; stream: SocketStream;
   var key: ClientKey
   var pid: int
   var config: LoaderClientConfig
+  var clonedFrom: int
   r.sread(key)
   r.sread(pid)
   r.sread(config)
+  r.sread(clonedFrom)
   stream.withPacketWriter w:
     if pid in ctx.clientData or key == default(ClientKey):
       w.swrite(false)
     else:
-      ctx.clientData[pid] = ClientData(pid: pid, key: key, config: config)
+      let client = ClientData(pid: pid, key: key, config: config)
+      ctx.clientData[pid] = client
+      if clonedFrom != -1:
+        let client2 = ctx.clientData[clonedFrom]
+        for item in client2.cacheMap:
+          inc item.refc
+        client.cacheMap = client2.cacheMap
       w.swrite(true)
   stream.sclose()
 
@@ -1138,13 +1146,14 @@ proc removeCachedItem*(loader: FileLoader; cacheId: int) =
     stream.sclose()
 
 proc addClient*(loader: FileLoader; key: ClientKey; pid: int;
-    config: LoaderClientConfig): bool =
+    config: LoaderClientConfig; clonedFrom: int): bool =
   let stream = loader.connect()
   stream.withLoaderPacketWriter loader, w:
     w.swrite(lcAddClient)
     w.swrite(key)
     w.swrite(pid)
     w.swrite(config)
+    w.swrite(clonedFrom)
   var r = stream.initPacketReader()
   r.sread(result)
   stream.sclose()