From 160d5ac76bce8a9e4162e9f7bd00136121a21eb6 Mon Sep 17 00:00:00 2001 From: jewelcodes Date: Wed, 27 Nov 2024 23:16:50 -0500 Subject: [PATCH] ipc: socket close() accounts for references --- src/ipc/sockinit.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ipc/sockinit.c b/src/ipc/sockinit.c index 6328152..fca93c3 100644 --- a/src/ipc/sockinit.c +++ b/src/ipc/sockinit.c @@ -225,6 +225,12 @@ int closeSocket(Thread *t, int sd) { return -EBADF; } + sock->refCount--; + if(sock->refCount) { + releaseLock(&lock); + return 0; + } + if(sock->peer) { // disconnect the socket from its peer // TODO: for future TCP sockets, terminate the connection here @@ -234,6 +240,7 @@ int closeSocket(Thread *t, int sd) { // and delete the socket socketUnregister(sock->globalIndex); + free(sock); closeIO(p, &p->io[sd]); releaseLock(&lock); return 0;