network/protocols/unix: Fix UnixDatagramEndpoint::Close().

1. Set fShutdownRead & fShutdownWrite. This is necessary
because in Send(), there is a lock-unlock dance between the
source and target sockets which could potentially race with
some other thread closing the socket. The "shutdown" state
is checked before actually writing, and so we need to set it
here. Otherwise, the other thread could allocate a new receive
FIFO for us, which we do not want.

2. Don't return early when unbinding, but only if there's an
error (there shouldn't be.)

3. Merely ASSERT() in Free() that closing was already done
and nothing remains to be deallocated.

Should fix #18535.
unix_dgram_test still passes.
This commit is contained in:
Augustin Cavalier 2023-08-03 17:08:03 -04:00
parent 363e0cdf69
commit 967ab75d8e

View File

@ -82,8 +82,13 @@ UnixDatagramEndpoint::Close()
UnixDatagramEndpointLocker endpointLocker(this);
if (IsBound())
RETURN_ERROR(UnixEndpoint::_Unbind());
fShutdownRead = fShutdownWrite = true;
if (IsBound()) {
status_t status = UnixEndpoint::_Unbind();
if (status != B_OK)
RETURN_ERROR(status);
}
_UnsetReceiveFifo();
@ -99,9 +104,10 @@ UnixDatagramEndpoint::Free()
UnixDatagramEndpointLocker endpointLocker(this);
_UnsetReceiveFifo();
ASSERT(fReceiveFifo == NULL);
ASSERT(fTargetEndpoint == NULL);
RETURN_ERROR(_Disconnect());
return B_OK;
}