Skip to content

Commit

Permalink
Stop ignoring real buffers shrunk to 0 size (#3157)
Browse files Browse the repository at this point in the history
* Stop ignoring real buffers shrunk to 0 size

Without this fix, trying to return allocated buffers to a BufferManager
with sizes updated to 0 can result in a memory leak.

* Rename ZeroSizeBuffer to NullEmptyBuffer
  • Loading branch information
celskeggs authored Jan 28, 2025
1 parent 82b6549 commit 464f4ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Svc/BufferManager/BufferManagerComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ namespace Svc {
// make sure component has been set up
FW_ASSERT(this->m_setup);
FW_ASSERT(m_buffers);
// check for empty buffers - this is just a warning since this component returns
// empty buffers if it can't allocate one.
if (fwBuffer.getSize() == 0) {
this->log_WARNING_HI_ZeroSizeBuffer();
// check for null, empty buffers - this is a warning because this component returns
// null, empty buffers if it can't allocate one.
// however, empty non-null buffers could potentially be previously allocated
// buffers with their size reduced. the user is allowed to make buffers smaller.
if (fwBuffer.getData() == nullptr && fwBuffer.getSize() == 0) {
this->log_WARNING_HI_NullEmptyBuffer();
this->m_emptyBuffs++;
return;
}
Expand Down
6 changes: 3 additions & 3 deletions Svc/BufferManager/Events.fppi
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ event NoBuffsAvailable(
format "No available buffers of size {}" \
throttle 10

@ The buffer manager received a zero-sized buffer as a return. Probably undetected empty buffer allocation
event ZeroSizeBuffer \
@ The buffer manager received a null pointer and zero-sized buffer as a return. Probably undetected failed buffer allocation
event NullEmptyBuffer \
severity warning high \
id 0x01 \
format "Received zero size buffer" \
format "Received null pointer and zero size buffer" \
throttle 10

0 comments on commit 464f4ea

Please sign in to comment.