From 154bb93c45836e1dafe1e9eb942d3cce084ece19 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Thu, 24 Nov 2022 19:36:21 +0800 Subject: [PATCH] mm: Terminate the backtrace array with one NULL pointer since one entry is enough to identify the end of back trace Signed-off-by: Xiang Xiao --- mm/mempool/mempool.c | 4 ++-- mm/mm_heap/mm.h | 6 +++--- mm/tlsf/mm_tlsf.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 04bbc0148f..b89a21868f 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -111,9 +111,9 @@ static inline void mempool_add_backtrace(FAR struct mempool_s *pool, if (pool->procfs.backtrace) { int result = backtrace(buf->backtrace, CONFIG_MM_BACKTRACE); - while (result < CONFIG_MM_BACKTRACE) + if (result < CONFIG_MM_BACKTRACE) { - buf->backtrace[result++] = NULL; + buf->backtrace[result] = NULL; } } else diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 10ee0596ac..952f2ed459 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -89,14 +89,14 @@ if ((heap)->mm_procfs.backtrace || (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) \ { \ int n = backtrace(tmp->backtrace, CONFIG_MM_BACKTRACE); \ - while (n < CONFIG_MM_BACKTRACE) \ + if (n < CONFIG_MM_BACKTRACE) \ { \ - tmp->backtrace[n++] = NULL; \ + tmp->backtrace[n] = NULL; \ } \ } \ else \ { \ - tmp->backtrace[0] = 0; \ + tmp->backtrace[0] = NULL; \ } \ } \ while (0) diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index 46afac384e..291a7ace30 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -156,9 +156,9 @@ static void memdump_backtrace(FAR struct mm_heap_s *heap, (tcb && tcb->flags & TCB_FLAG_HEAPDUMP)) { int ret = backtrace(dump->backtrace, CONFIG_MM_BACKTRACE); - while (ret < CONFIG_MM_BACKTRACE) + if (ret < CONFIG_MM_BACKTRACE) { - dump->backtrace[ret++] = NULL; + dump->backtrace[ret] = NULL; } } # endif