Skip to content

Commit

Permalink
[TV] Add some null checks for both the TCP and the UDP enpoints to pr…
Browse files Browse the repository at this point in the history
…event shutdown crashes
  • Loading branch information
vivien-apple committed Sep 30, 2024
1 parent 6bbe1d6 commit df3476f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/inet/TCPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ void TCPEndPoint::StartConnectTimerIfSet()

void TCPEndPoint::StopConnectTimer()
{
GetSystemLayer().CancelTimer(TCPConnectTimeoutHandler, this);
auto * systemLayer = &GetSystemLayer();
VerifyOrReturn(nullptr != systemLayer);

systemLayer->CancelTimer(TCPConnectTimeoutHandler, this);
}

void TCPEndPoint::TCPConnectTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState)
Expand Down Expand Up @@ -464,7 +467,10 @@ void TCPEndPoint::StartTCPUserTimeoutTimer()

void TCPEndPoint::StopTCPUserTimeoutTimer()
{
GetSystemLayer().CancelTimer(TCPUserTimeoutHandler, this);
auto * systemLayer = &GetSystemLayer();
VerifyOrReturn(nullptr != systemLayer);

systemLayer->CancelTimer(TCPUserTimeoutHandler, this);
mUserTimeoutTimerRunning = false;
}

Expand Down
6 changes: 5 additions & 1 deletion src/inet/TCPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,11 @@ void TCPEndPointImplSockets::DoCloseImpl(CHIP_ERROR err, State oldState)
}
}

static_cast<System::LayerSockets &>(GetSystemLayer()).StopWatchingSocket(&mWatch);
auto * systemLayer = &GetSystemLayer();
if (nullptr != systemLayer)
{
static_cast<System::LayerSockets &>(GetSystemLayer()).StopWatchingSocket(&mWatch);
}
close(mSocket);
mSocket = kInvalidSocketFd;
}
Expand Down
6 changes: 5 additions & 1 deletion src/inet/UDPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ void UDPEndPointImplSockets::CloseImpl()
{
if (mSocket != kInvalidSocketFd)
{
static_cast<System::LayerSockets *>(&GetSystemLayer())->StopWatchingSocket(&mWatch);
auto * systemLayer = &GetSystemLayer();
if (nullptr != systemLayer)
{
static_cast<System::LayerSockets *>(systemLayer)->StopWatchingSocket(&mWatch);
}
close(mSocket);
mSocket = kInvalidSocketFd;
}
Expand Down

0 comments on commit df3476f

Please sign in to comment.