Repository navigation
py/gc: keep a heap area whose only live block is its first one - #11895
lynt-smitka wants to merge 2 commits into
Conversation
The sweep took last_used_block == 0 for "empty". It is also 0 when block 0 is the only one in use, so such an area was given back to the port with a live object in it.
dhalbert
left a comment
There was a problem hiding this comment.
Uh, oh! Thanks for finding! It would be good to submit this upstream as well. I recently submitted another gc bug fix: micropython#19802, which could be a model. Note in that one I added a test (which had to be in coverage.c), so a test there or if possible in Python would be good. It may need to be in coverage.c for reproducibility.
|
My "Requested Change" is to add a test. Submitting upstream can be done later. |
|
@dhalbert A test is a bit complicated then I taught. The fix is only compiled with |
The unix coverage build now lets the collector add and free heap areas, as it does on the boards. It starts with one of its four areas and gets the others on demand, so the total heap size is unchanged. The new test fails without the fix in the previous commit.
The sweep frees a heap area when
last_used_block == 0, taking that to mean the area is empty. But it is also 0 when only the first block is used. Then the area is freed while an object still lives in it.Code to reproduce it in REPL:
Before:
tuple 411 now reads (412,) - same address as the next one: TrueAfter:
no corruptionTested on a Feather ESP32-S3 TFT.
MicroPython master has the same line.
The code was written with the help of an LLM.