diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index d5e90568f7af84..32b10c62c5d720 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -371,20 +371,15 @@ void UDPEndPointImplLwIP::LwIPReceiveUDPMessage(void * arg, struct udp_pcb * pcb pktInfo->DestPort = pcb->local_port; } - ep->Retain(); + // TODO: add thread-safe reference counting for UDP endpoints CHIP_ERROR err = ep->GetSystemLayer().ScheduleLambda([ep, p = System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(buf)] { ep->HandleDataReceived(System::PacketBufferHandle::Adopt(p)); - ep->Release(); }); if (err == CHIP_NO_ERROR) { // If ScheduleLambda() succeeded, it has ownership of the buffer, so we need to release it (without freeing it). static_cast(std::move(buf).UnsafeRelease()); } - else - { - ep->Release(); - } } CHIP_ERROR UDPEndPointImplLwIP::SetMulticastLoopback(IPVersion aIPVersion, bool aLoopback) diff --git a/src/inet/UDPEndPointImplOpenThread.cpp b/src/inet/UDPEndPointImplOpenThread.cpp index 02f11ba30bdf75..2f78e80a4253ef 100644 --- a/src/inet/UDPEndPointImplOpenThread.cpp +++ b/src/inet/UDPEndPointImplOpenThread.cpp @@ -98,18 +98,15 @@ void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage, } payload->SetDataLength(static_cast(msgLen)); - ep->Retain(); - auto * buf = std::move(payload).UnsafeRelease(); - CHIP_ERROR err = ep->GetSystemLayer().ScheduleLambda([ep, buf] { - ep->HandleDataReceived(System::PacketBufferHandle::Adopt(buf)); - ep->Release(); - }); + // TODO: add thread-safe reference counting for UDP endpoints + auto * buf = std::move(payload).UnsafeRelease(); + CHIP_ERROR err = + ep->GetSystemLayer().ScheduleLambda([ep, buf] { ep->HandleDataReceived(System::PacketBufferHandle::Adopt(buf)); }); if (err != CHIP_NO_ERROR) { // Make sure we properly clean up buf and ep, since our lambda will not // run. payload = System::PacketBufferHandle::Adopt(buf); - ep->Release(); } }