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 /src/io | |
| parent | 62586dc23790732e66add5b27d4d37f1a56b41e0 (diff) | |
| download | chawan-f95e720e4a621d47c16a0c77d996e4878ad0a8b3.tar.gz | |
dynstream: fix memory leak
now I know why overloading dealloc felt wrong
Diffstat (limited to 'src/io')
| -rw-r--r-- | src/io/dynstream.nim | 7 |
1 files changed, 5 insertions, 2 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 |