diff --git a/include/malloc.h b/include/malloc.h index 1de6336f07b..d28e3398c6d 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -35,7 +35,7 @@ #define PID_MM_FREE ((pid_t)-4) #define PID_MM_ALLOC ((pid_t)-3) -#define PID_MM_INVALID ((pid_t)-2) +#define PID_MM_LEAK ((pid_t)-2) #define PID_MM_MEMPOOL ((pid_t)-1) /* For Linux and MacOS compatibility */ diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 60994326ba9..af3a92677bf 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -412,10 +412,8 @@ mempool_info_task(FAR struct mempool_s *pool, #if CONFIG_MM_BACKTRACE < 0 else if (task->pid == PID_MM_ALLOC) { - size_t count = pool->nalloc; - - info.aordblks += count; - info.uordblks += count * pool->blocksize; + info.aordblks += pool->nalloc; + info.uordblks += pool->nalloc * pool->blocksize; } #else else @@ -425,15 +423,12 @@ mempool_info_task(FAR struct mempool_s *pool, list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s, node) { - if (task->pid == buf->pid || task->pid == PID_MM_ALLOC || - (task->pid == PID_MM_INVALID && - nxsched_get_tcb(buf->pid) == NULL)) + if ((task->pid == PID_MM_ALLOC || task->pid == buf->pid || + (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) && + buf->seqno >= task->seqmin && buf->seqno <= task->seqmax) { - if (buf->seqno >= task->seqmin && buf->seqno <= task->seqmax) - { - info.aordblks++; - info.uordblks += pool->blocksize; - } + info.aordblks++; + info.uordblks += pool->blocksize; } } } @@ -491,7 +486,7 @@ void mempool_memdump(FAR struct mempool_s *pool, list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s, node) { - if ((buf->pid == dump->pid || dump->pid == PID_MM_ALLOC) && + if ((dump->pid == PID_MM_ALLOC || dump->pid == buf->pid) && buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax) { # if CONFIG_MM_BACKTRACE > 0 diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c index 539ab757698..7257ef246ce 100644 --- a/mm/mm_heap/mm_mallinfo.c +++ b/mm/mm_heap/mm_mallinfo.c @@ -87,7 +87,9 @@ static void mallinfo_handler(FAR struct mm_allocnode_s *node, FAR void *arg) static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, FAR void *arg) { - FAR struct mm_mallinfo_handler_s *handle = arg; + FAR struct mm_mallinfo_handler_s *handler = arg; + FAR const struct malltask *task = handler->task; + FAR struct mallinfo_task *info = handler->info; size_t nodesize = SIZEOF_MM_NODE(node); /* Check if the node corresponds to an allocated memory chunk */ @@ -96,30 +98,25 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, { DEBUGASSERT(nodesize >= SIZEOF_MM_ALLOCNODE); #if CONFIG_MM_BACKTRACE < 0 - if (handle->task->pid == PID_MM_ALLOC) + if (task->pid == PID_MM_ALLOC) { - handle->info->aordblks++; - handle->info->uordblks += nodesize; + info->aordblks++; + info->uordblks += nodesize; } #else - if (handle->task->pid == PID_MM_ALLOC || - handle->task->pid == node->pid || - (handle->task->pid == PID_MM_INVALID && - nxsched_get_tcb(node->pid) == NULL)) + if ((task->pid == PID_MM_ALLOC || task->pid == node->pid || + (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) && + node->seqno >= task->seqmin && node->seqno <= task->seqmax) { - if (node->seqno >= handle->task->seqmin && - node->seqno <= handle->task->seqmax) - { - handle->info->aordblks++; - handle->info->uordblks += nodesize; - } + info->aordblks++; + info->uordblks += nodesize; } #endif } - else if (handle->task->pid == PID_MM_FREE) + else if (task->pid == PID_MM_FREE) { - handle->info->aordblks++; - handle->info->uordblks += nodesize; + info->aordblks++; + info->uordblks += nodesize; } } diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index 4ab3f50ce94..1567326a8ca 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -80,7 +80,7 @@ void mm_dump_handler(FAR struct tcb_s *tcb, FAR void *arg) struct mallinfo_task info; struct malltask task; - task.pid = tcb ? tcb->pid : PID_MM_INVALID; + task.pid = tcb ? tcb->pid : PID_MM_LEAK; task.seqmin = 0; task.seqmax = ULONG_MAX; info = mm_mallinfo_task(arg, &task); diff --git a/mm/mm_heap/mm_memdump.c b/mm/mm_heap/mm_memdump.c index 131d2181f82..1406a76c3ae 100644 --- a/mm/mm_heap/mm_memdump.c +++ b/mm/mm_heap/mm_memdump.c @@ -61,7 +61,7 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg) #if CONFIG_MM_BACKTRACE < 0 if (dump->pid == PID_MM_ALLOC) #else - if ((dump->pid == PID_MM_ALLOC || node->pid == dump->pid) && + if ((dump->pid == PID_MM_ALLOC || dump->pid == node->pid) && node->seqno >= dump->seqmin && node->seqno <= dump->seqmax) #endif { diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index 554ea8dfcba..5c66f26dea8 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -284,6 +284,8 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used, FAR struct memdump_backtrace_s *buf; #endif FAR struct mm_mallinfo_handler_s *handler = user; + FAR const struct malltask *task = handler->task; + FAR struct mallinfo_task *info = handler->info; #if CONFIG_MM_BACKTRACE >= 0 size -= sizeof(struct memdump_backtrace_s); @@ -292,30 +294,25 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used, if (used) { #if CONFIG_MM_BACKTRACE < 0 - if (handler->task->pid == PID_MM_ALLOC) + if (task->pid == PID_MM_ALLOC) { - handler->info->aordblks++; - handler->info->uordblks += size; + info->aordblks++; + info->uordblks += size; } #else - if (handler->task->pid == PID_MM_ALLOC || - handler->task->pid == buf->pid || - (handler->task->pid == PID_MM_INVALID && - nxsched_get_tcb(buf->pid) == NULL)) + if ((task->pid == PID_MM_ALLOC || task->pid == buf->pid || + (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) && + buf->seqno >= task->seqmin && buf->seqno <= task->seqmax) { - if (buf->seqno >= handler->task->seqmin && - buf->seqno <= handler->task->seqmax) - { - handler->info->aordblks++; - handler->info->uordblks += size; - } + info->aordblks++; + info->uordblks += size; } #endif } - else if (handler->task->pid == PID_MM_FREE) + else if (task->pid == PID_MM_FREE) { - handler->info->aordblks++; - handler->info->uordblks += size; + info->aordblks++; + info->uordblks += size; } #endif } @@ -417,9 +414,9 @@ static void memdump_handler(FAR void *ptr, size_t size, int used, if (used) { #if CONFIG_MM_BACKTRACE < 0 - if (pid == PID_MM_ALLOC) + if (dump->pid == PID_MM_ALLOC) #else - if ((dump->pid == PID_MM_ALLOC || buf->pid == dump->pid) && + if ((dump->pid == PID_MM_ALLOC || dump->pid == buf->pid) && buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax) #endif {