aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-04 17:01:51 +0200
committerbptato <nincsnevem662@gmail.com>2024-10-04 17:06:01 +0200
commitf95e720e4a621d47c16a0c77d996e4878ad0a8b3 (patch)
tree7c6254a6bf2d6c05029ba2ac7fac42eb6ba2e2f2 /src
parent62586dc23790732e66add5b27d4d37f1a56b41e0 (diff)
downloadchawan-f95e720e4a621d47c16a0c77d996e4878ad0a8b3.tar.gz
dynstream: fix memory leak
now I know why overloading dealloc felt wrong
Diffstat (limited to 'src')
-rw-r--r--src/io/dynstream.nim7
-rw-r--r--src/local/pager.nim3
2 files changed, 6 insertions, 4 deletions
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim
index 4a711c12..4138f153 100644
--- a/src/io/dynstream.nim
+++ b/src/io/dynstream.nim
@@ -11,7 +11,7 @@ type
blocking*: bool #TODO move to posixstream
closed: bool
-# Semantics of this function are those of POSIX read(2): that is, it may return
+# Semantics of this function are those of POSIX read(3): that is, it may return
# a result that is lower than `len`, and that does not mean the stream is
# finished.
# isend must be set by implementations when the end of the stream is reached.
@@ -255,11 +255,14 @@ proc sendDataLoop*(ps: PosixStream; mem: MaybeMappedMemory) =
if not mem.fromMmap:
ps.sendDataLoop(mem.p, mem.len)
-proc dealloc*(mem: MaybeMappedMemory) =
+template dealloc*(mem: MaybeMappedMemory) {.error: "use deallocMem".} = discard
+
+proc deallocMem*(mem: MaybeMappedMemory) =
if mem.fromMmap:
discard munmap(mem.p0, mem.p0len)
else:
dealloc(mem.p0)
+ dealloc(pointer(mem))
proc drain*(ps: PosixStream) =
assert not ps.blocking
diff --git a/src/local/pager.nim b/src/local/pager.nim
index d3b4d860..0c4588fd 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -624,8 +624,7 @@ proc loadCachedImage(pager: Pager; container: Container; image: PosBitmap;
return
let blob = newBlob(mem.p, mem.len, "image/x-sixel",
(proc(opaque, p: pointer) =
- let mem = cast[MaybeMappedMemory](opaque)
- dealloc(mem)
+ deallocMem(cast[MaybeMappedMemory](opaque))
), mem
)
container.redraw = true