Skip to content

Commit

Permalink
ipc: socket close() accounts for references
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Nov 28, 2024
1 parent e7249b1 commit 160d5ac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ipc/sockinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 160d5ac

Please sign in to comment.