Repository navigation
Updater: fall back to a 256 byte buffer when the sector buffer cannot be allocated - #9344
Open
sanerdemirel wants to merge 7 commits into
Open
sanerdemirel wants to merge 7 commits into
sanerdemirel wants to merge 7 commits into
Conversation
mcspr
reviewed
Nov 10, 2026
Replacing operator new[] leaks into the whole test runtime and does not work under valgrind. The allocation tests and the mockFreeHeap seam go; only the change in Updater.cpp stays.
Author
|
Thanks for the review. You are right: replacing I have dropped the allocation-hook tests from this PR. What is left is the change in When your mocking allocator with |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9342.
UpdaterClass::begin()picks a 4 KB write buffer when total free heap is above 8 KB, and a 256 byte buffer otherwise. It then makes one allocation. If the heap is fragmented, there can be more than 8 KB free but no free block of 4 KB. The allocation fails andbegin()returnsUPDATE_ERROR_OOM, although the update would work with 256 bytes.As suggested in the issue,
begin()now walks through{FLASH_SECTOR_SIZE, 256}and usesnew (std::nothrow)for each size. The first size that works is used. If both fail, it still reportsUPDATE_ERROR_OOM.The low-heap rule is unchanged: with 8 KB or less free, only 256 is tried, so the buffer does not take the last of the heap.
The diff is
cores/esp8266/Updater.cpponly, +7/-5. The 256 byte path was already used when the heap was low, so no code needs to learn about a new buffer size.Tests
This PR adds no new tests. An earlier version had host tests that replaced the nothrow
operator new[]for the whole test binary, to refuse chosen sizes. As discussed in the review, that is the wrong level, and under valgrind the hook is never called, so I dropped them. The fallback tests can follow on top of a mocking allocator that works under valgrind:begin()still succeeds with 256.begin()reportsUPDATE_ERROR_OOM, and the updater can be used again afterwards.Results on the current head, on Ubuntu 24.04 with g++ 13 and clang-format-18:
make FORCE32=0 D=1 testpasses: 89 test cases, 33214 assertions. The existing Updater host tests run against the changedbegin().make CI(-Werror, valgrind, coverage) passes: 0 errors, no leaks reported.tests/restyle.shwith clang-format-18 changes nothing.Not tested
begin().