diff options
author | bptato <nincsnevem662@gmail.com> | 2024-10-04 17:01:51 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-10-04 17:06:01 +0200 |
commit | f95e720e4a621d47c16a0c77d996e4878ad0a8b3 (patch) | |
tree | 7c6254a6bf2d6c05029ba2ac7fac42eb6ba2e2f2 | |
parent | 62586dc23790732e66add5b27d4d37f1a56b41e0 (diff) | |
download | chawan-f95e720e4a621d47c16a0c77d996e4878ad0a8b3.tar.gz |
dynstream: fix memory leak
now I know why overloading dealloc felt wrong
-rw-r--r-- | adapter/img/resize.nim | 4 | ||||
-rw-r--r-- | adapter/img/sixel.nim | 2 | ||||
-rw-r--r-- | adapter/img/stbi.nim | 2 | ||||
-rw-r--r-- | src/io/dynstream.nim | 7 | ||||
-rw-r--r-- | src/local/pager.nim | 3 |
5 files changed, 10 insertions, 8 deletions
diff --git a/adapter/img/resize.nim b/adapter/img/resize.nim index 5bd29b63..bd3b8c9a 100644 --- a/adapter/img/resize.nim +++ b/adapter/img/resize.nim @@ -54,7 +54,7 @@ proc main() = doAssert stbir_resize_uint8(addr src.p[0], srcWidth, srcHeight, 0, addr dst.p[1], dstWidth, dstHeight, 0, 4) == 1 os.sendDataLoop(dst) - dealloc(src) - dealloc(dst) + deallocMem(src) + deallocMem(dst) main() diff --git a/adapter/img/sixel.nim b/adapter/img/sixel.nim index 15a7166e..7eb7be13 100644 --- a/adapter/img/sixel.nim +++ b/adapter/img/sixel.nim @@ -553,6 +553,6 @@ proc main() = let p = cast[ptr UncheckedArray[RGBAColorBE]](src.p) os.encode(p.toOpenArray(0, n - 1), width, height, offx, offy, cropw, palette, halfdump) - dealloc(src) + deallocMem(src) main() diff --git a/adapter/img/stbi.nim b/adapter/img/stbi.nim index dec221f1..0747d5d7 100644 --- a/adapter/img/stbi.nim +++ b/adapter/img/stbi.nim @@ -170,6 +170,6 @@ proc main() = of "jpeg": stbi_write_jpg_to_func(myWriteFunc, nil, cint(width), cint(height), 4, p, quality) - dealloc(src) + deallocMem(src) main() 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 |