Skip to content

downlink: fix double free when block queue is full - #140

Merged
sam-golioth merged 1 commit into
mainfrom
fix_downlink_oom
Feb 20, 2026
Merged

downlink: fix double free when block queue is full#140
sam-golioth merged 1 commit into
mainfrom
fix_downlink_oom

Conversation

@sam-golioth

Copy link
Copy Markdown
Contributor

When we are unable to allocate a downlink block, we close the downlink and return an error to the CoAP client. But returning an error to the CoAP client also eventually results in closing the downlink. Closing the downlink involves flushing the block queue and releasing the currently held block, and doing it twice leads to a double free of the currently held block. To fix, we do not close the downlink directly when we are unable to allocate a block, instead we just return an error to the CoAP client.

This bug was introduced in #137 which added the proper handling for errors in CoAP callbacks during downlink.

When we are unable to allocate a downlink block, we close the
downlink and return an error to the CoAP client. But returning
an error to the CoAP client also eventually results in closing
the downlink. Closing the downlink involves flushing the block
queue and releasing the currently held block, and doing it twice
leads to a double free of the currently held block. To fix, we
do not close the downlink directly when we are unable to allocate
a block, instead we just return an error to the CoAP client.

Signed-off-by: Sam Friedman <sam@golioth.io>

@hasheddan hasheddan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@sam-golioth
sam-golioth merged commit 604991d into main Feb 20, 2026
9 of 10 checks passed
@sam-golioth
sam-golioth deleted the fix_downlink_oom branch February 20, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants