Skip to content

Commit

Permalink
Fix locking in UDPEndPoint::SendMsgImpl() (#10533)
Browse files Browse the repository at this point in the history
#### Problem

If `GetPCB()` were to fail, `SendMsgImpl()` would return with the
LwIP lock held.

#### Change overview

Unlock before returning.

#### Testing

None. We don't currently have a way to either (a) force `GetPCB` to
fail, or (b) detect whether the LwIP lock is held.
  • Loading branch information
kpschoedel authored and pull[bot] committed Oct 22, 2021
1 parent cc44d06 commit 2405840
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/inet/UDPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ CHIP_ERROR UDPEndPoint::ListenImpl()

CHIP_ERROR UDPEndPoint::SendMsgImpl(const IPPacketInfo * pktInfo, System::PacketBufferHandle && msg, uint16_t sendFlags)
{
CHIP_ERROR res = CHIP_NO_ERROR;
const IPAddress & destAddr = pktInfo->DestAddress;

if (!msg.HasSoleOwnership())
Expand All @@ -242,8 +241,12 @@ CHIP_ERROR UDPEndPoint::SendMsgImpl(const IPPacketInfo * pktInfo, System::Packet
LOCK_TCPIP_CORE();

// Make sure we have the appropriate type of PCB based on the destination address.
res = GetPCB(destAddr.Type());
ReturnErrorOnFailure(res);
CHIP_ERROR res = GetPCB(destAddr.Type());
if (res != CHIP_NO_ERROR)
{
UNLOCK_TCPIP_CORE();
return res;
}

// Send the message to the specified address/port.
// If an outbound interface has been specified, call a specific version of the UDP sendto()
Expand Down

0 comments on commit 2405840

Please sign in to comment.