Skip to content

Commit

Permalink
Make PacketBufferHandle::Get private again. (#17567)
Browse files Browse the repository at this point in the history
People who need a raw buffer that they own should be calling
UnsafeRelease.  Get() should not have been made public.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 12, 2023
1 parent 1a8b607 commit 282f0c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/inet/UDPEndPointImplOpenThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,16 @@ void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage,
payload->SetDataLength(static_cast<uint16_t>(msgLen + sizeof(IPPacketInfo)));

ep->Retain();
CHIP_ERROR err = ep->GetSystemLayer().ScheduleLambda([ep, p = payload.Get()] {
ep->HandleDataReceived(System::PacketBufferHandle::Adopt(p));
auto * buf = std::move(payload).UnsafeRelease();
CHIP_ERROR err = ep->GetSystemLayer().ScheduleLambda([ep, buf] {
ep->HandleDataReceived(System::PacketBufferHandle::Adopt(buf));
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<void>(std::move(payload).UnsafeRelease());
}
else
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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/system/SystemPacketBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,6 @@ class DLL_EXPORT PacketBufferHandle
#endif
}

PacketBuffer * Get() const { return mBuffer; }

protected:
#if CHIP_SYSTEM_CONFIG_USE_LWIP
// For use via LwIPPacketBufferView only.
Expand All @@ -679,6 +677,8 @@ class DLL_EXPORT PacketBufferHandle
return PacketBufferHandle(buffer);
}

PacketBuffer * Get() const { return mBuffer; }

bool operator==(const PacketBufferHandle & aOther) { return mBuffer == aOther.mBuffer; }

#if CHIP_SYSTEM_PACKETBUFFER_HAS_RIGHTSIZE
Expand Down

0 comments on commit 282f0c2

Please sign in to comment.