Skip to content

Commit

Permalink
Make sure we clean up properly if StartWatchingSocket fails. (#28245)
Browse files Browse the repository at this point in the history
If StartWatchingSocket failed (e.g. due to us being out of socket watch pool
space), we would leave the UDPEndPointImplSockets in a bad state where its
destructor would try to treat the un-initialized mWatch value as a pointer.

The fix is to make sure we clean up properly on StartWatchingSocket failure.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 25, 2023
1 parent e9cc426 commit 3901715
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/inet/UDPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,14 @@ CHIP_ERROR UDPEndPointImplSockets::GetSocket(IPAddressType addressType)
{
return CHIP_ERROR_POSIX(errno);
}
ReturnErrorOnFailure(static_cast<System::LayerSockets *>(&GetSystemLayer())->StartWatchingSocket(mSocket, &mWatch));
CHIP_ERROR err = static_cast<System::LayerSockets *>(&GetSystemLayer())->StartWatchingSocket(mSocket, &mWatch);
if (err != CHIP_NO_ERROR)
{
// Our mWatch is not valid; make sure we never use it.
close(mSocket);
mSocket = kInvalidSocketFd;
return err;
}

mAddrType = addressType;

Expand Down

0 comments on commit 3901715

Please sign in to comment.