Skip to content

Commit

Permalink
Fix PacketBuffer allocation size when using LwIP (project-chip#8226)
Browse files Browse the repository at this point in the history
#### Problem

LwIP `pbuf_alloc()` was called with a size including the `struct pbuf`
header, but expects the size to exclude that.

#### Change overview

Call `pbuf_alloc()` with the correct size.

This imports a fragment of openweave/openweave-core#608

#### Testing

Added `PacketBuffer::kMaxSizeWithoutReserve` to the cases checked
by `PacketBufferTest::CheckNew()`.
  • Loading branch information
kpschoedel authored Jul 9, 2021
1 parent 2374d80 commit 5537680
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/system/SystemPacketBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ PacketBufferHandle PacketBufferHandle::New(size_t aAvailableSize, uint16_t aRese
#if CHIP_SYSTEM_PACKETBUFFER_STORE == CHIP_SYSTEM_PACKETBUFFER_STORE_LWIP_POOL || \
CHIP_SYSTEM_PACKETBUFFER_STORE == CHIP_SYSTEM_PACKETBUFFER_STORE_LWIP_CUSTOM

lPacket = static_cast<PacketBuffer *>(pbuf_alloc(PBUF_RAW, static_cast<uint16_t>(lBlockSize), PBUF_POOL));
lPacket = static_cast<PacketBuffer *>(pbuf_alloc(PBUF_RAW, static_cast<uint16_t>(lAllocSize), PBUF_POOL));

SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS();

Expand Down
2 changes: 1 addition & 1 deletion src/system/tests/TestSystemPacketBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class PacketBufferTest
std::vector<PacketBufferHandle> handles;
};

const uint16_t sTestReservedSizes[] = { 0, 10, 128, 1536, PacketBufferTest::kBlockSize };
const uint16_t sTestReservedSizes[] = { 0, 10, 128, 1536, PacketBuffer::kMaxSizeWithoutReserve, PacketBufferTest::kBlockSize };
const uint16_t sTestLengths[] = { 0, 1, 10, 128, PacketBufferTest::kBlockSize, UINT16_MAX };

PacketBufferTest::TestContext sContext = {
Expand Down

0 comments on commit 5537680

Please sign in to comment.