diff options
author | bptato <nincsnevem662@gmail.com> | 2024-09-02 20:47:11 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-09-02 20:47:24 +0200 |
commit | 78e6d4577e5cfce78c7052f7186667e2eab209d5 (patch) | |
tree | bfa26776640a1564c4a4eb064813caccb47dbeb0 /src/io | |
parent | f73926306811359c47b589bf860ddccb0a1ceb14 (diff) | |
download | chawan-78e6d4577e5cfce78c7052f7186667e2eab209d5.tar.gz |
loader: fix some fd leaks
+ be a bit more paranoid about double closes
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/dynstream.nim | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim index 9e23a8ae..2bfa02f5 100644 --- a/src/io/dynstream.nim +++ b/src/io/dynstream.nim @@ -9,6 +9,7 @@ type DynStream* = ref object of RootObj isend*: bool blocking*: bool #TODO move to posixstream + closed: bool # Semantics of this function are those of POSIX read(2): that is, it may return # a result that is lower than `len`, and that does not mean the stream is @@ -155,7 +156,9 @@ method seek*(s: PosixStream; off: int) = raisePosixIOError() method sclose*(s: PosixStream) = + assert not s.closed discard close(s.fd) + s.closed = true proc newPosixStream*(fd: FileHandle): PosixStream = return PosixStream(fd: fd, blocking: true) @@ -214,7 +217,9 @@ method seek*(s: SocketStream; off: int) = doAssert false method sclose*(s: SocketStream) = + assert not s.closed s.source.close() + s.closed = true # see serversocket.nim for an explanation {.compile: "connect_unix.c".} @@ -301,7 +306,9 @@ method sendData*(s: BufStream; buffer: pointer; len: int): int = return len method sclose*(s: BufStream) = + assert not s.closed s.source.sclose() + s.closed = true proc flushWrite*(s: BufStream): bool = s.source.setBlocking(false) @@ -340,7 +347,9 @@ method seek*(s: DynFileStream; off: int) = s.file.setFilePos(int64(off)) method sclose*(s: DynFileStream) = + assert not s.closed s.file.close() + s.closed = true method sflush*(s: DynFileStream) = s.file.flushFile() |