Repository navigation
[kernel][mem] fix false MEM_POOL assert when freeing block before heap_end - #12014
Conversation
…p_end rt_smem_free() validated mem->next by requiring the next item's pool pointer to be the current pool. For the last block, mem->next points at the heap_end sentinel. Older/vendor small-mem pools may keep only the used bit in the sentinel's pool_ptr, so MEM_POOL(heap_end) is NULL and the assertion fires although the heap is consistent. Accept mem->next == heap_end offset explicitly and keep the same-pool check for every other next item. Changing the check to mem->prev is not equivalent: prev describes the previous block (0 for the first block), so it would not validate the next pointer. Reproduced on the host with the real mem.c by making the sentinel carry only the used bit: the old assertion aborts, the new one passes. Added a core.mem utest that allocates the last block, simulates that sentinel state, frees it, and verifies the heap is fully merged. Normal middle, first and last frees/merges remain covered by the existing test. No functional change for well-formed heaps.
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-11-10 09:05 CST)
📝 Review Instructions
|
|
BernardXiong
left a comment
There was a problem hiding this comment.
结论:未发现阻塞问题,可以合并。
rt_smem_free() 用 next == heap_end_offset 放行 heap_end 哨兵,其它 next 仍走 MEM_POOL() 的同 pool 校验,语义正确;新增的 utest 覆盖了最后一块 + 哨兵 pool_ptr 只带 used bit 的场景。
CI:108 pass / 4 skip,全部通过。
中文
问题
释放堆上最后一块时,
rt_smem_free()用MEM_POOL(next)校验会误断言:最后一块的next是heap_end哨兵,部分实现里哨兵只带 used bit(#10632)。改动
src/mem.c:next == heap_end则放行;其它 next 仍查同 poolmem->prev(语义不同)src/utest/mem_tc.c:加回归用例验证
主机
core.mem通过;未跑板级。English
Problem
Freeing the last heap block false-asserts in
rt_smem_free():nextis theheap_endsentinel, and some pools only store the used bit there (#10632).Changes
src/mem.c: allownext == heap_end; keep same-pool check otherwisemem->prevsrc/utest/mem_tc.c: regression testTest plan
Host
core.memOK; no board run.Fixes #10632