Repository navigation
mm/mm_heap: memdump and mm_foreach() fixes - #22275
Merged
xiaoxiang781216 merged 5 commits intoNov 25, 2026
Merged
Conversation
mm_memdump() of both heap managers now keeps its own copy of the request instead of a pointer to the caller's. With CONFIG_MM_BACKTRACE_SEQNO, a request whose seqmin and seqmax are both 0 (a caller that leaves them unset) is taken as the whole sequence range, 0 to ULONG_MAX, instead of sequence number 0 only. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Should not set to 0 again, as already memset. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
The '%' of the "%*p" conversion in memdump_allocnode() sat in the string literal that is only compiled with CONFIG_MM_BACKTRACE_SEQNO. Without it the format read "...%9zu*p %s", so the address was printed as the text "*p" and "%s" took the width argument. Keep the whole conversion in the unconditional literal. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
The group heap prototypes of include/nuttx/kmalloc.h take a struct task_group_s pointer. Forward-declare the structure, so that they do not depend on its definition in nuttx/sched.h having been seen. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: anjiahao <anjiahao@xiaomi.com>
On the first loop iteration prev is NULL. If the heap start node has a corrupted preceding field with MM_PREVFREE_BIT set, the short-circuit evaluation of the DEBUGASSERT falls through to MM_SIZEOF_NODE(prev) which dereferences NULL. Add a prev == NULL guard so the preceding-size consistency check is skipped for the first node, which has no predecessor. CID 1817303 (#1 of 1): Dereference null pointer (NULL_RETURNS) Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
huojianchaoyy
requested review from
Donny9,
pussuw and
xiaoxiang781216
as code owners
November 24, 2026 12:47
xiaoxiang781216
approved these changes
Nov 24, 2026
GUIDINGLI
approved these changes
Nov 24, 2026
|
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.
Note: Please adhere to Contributing Guidelines.
Summary
Heap fixes from Xiaomi Vela, split out of #22206 as asked in its review.
mm_memdump()keeps its own copy of the request; withCONFIG_MM_BACKTRACE_SEQNO, seqmin = seqmax = 0 means the whole sequence range. mmdump: fix pid ignored in foreach then keeps the pid of the request.CONFIG_MM_BACKTRACE > 0and withoutCONFIG_MM_BACKTRACE_SEQNO, the format ofmemdump_allocnode()lost the '%' of "%*p" and passed an int to "%s" (crash on sim, see Testing).struct task_group_sinkmalloc.h, for the group heap prototypes.mm_memdump()walks the heap withmm_foreach(), whose check of the first node read its NULL predecessor when the node is corrupted.Impact
CONFIG_MM_BACKTRACE_SEQNO, a memdump request with seqmin = seqmax = 0 dumps all sequence numbers instead of sequence number 0 only.Testing
Host: Ubuntu 22.04 x86_64, GCC 13.4.0, CMake 3.23 + Ninja 1.10. Base: master 25b649e.
./tools/checkpatch.sh -c -u -m -g HEAD~5..HEADpasses.sim:nshwithCONFIG_MM_BACKTRACE=8 CONFIG_MM_BACKTRACE_SEQNO=n,echo used > /proc/memdump:With
CONFIG_MM_BACKTRACE_SEQNO=y(the default) the/proc/memdumpoutput (used, pid, leak) is the same as on master.Builds (CMake):
sim:nshwith backtrace 8 / 0, with and withoutMM_BACKTRACE_SEQNO, and with the TLSF manager with and withoutMM_BACKTRACE_SEQNO;/proc/memdumpruns on the backtrace 8, backtrace 0 and TLSF builds.Not tested: real hardware.