gpt4 book ai didi

c++ - valgrind memcheck 是否支持检查 mmap

转载 作者:可可西里 更新时间:2023-11-01 18:29:33 26 4
gpt4 key购买 nike

我正在尝试使用 valgrind 来检测内存泄漏。它适用于堆泄漏(即来自 malloc 或 new 的内存分配)。但是,它是否支持在 Linux 中检查 mmap 泄漏?

谢谢张

最佳答案

不直接,很难调试,看valgrind.h

   VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a
heap block -- that will be used by the client program -- is allocated.
It's best to put it at the outermost level of the allocator if possible;
for example, if you have a function my_alloc() which calls
internal_alloc(), and the client request is put inside internal_alloc(),
stack traces relating to the heap block will contain entries for both
my_alloc() and internal_alloc(), which is probably not what you want.

For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out
custom blocks from within a heap block, B, that has been allocated with
malloc/calloc/new/etc, then block B will be *ignored* during leak-checking
-- the custom blocks will take precedence.

VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK. For
Memcheck, it does two things:

- It records that the block has been deallocated. This assumes that the
block was annotated as having been allocated via
VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.

- It marks the block as being unaddressable.

VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a
heap block is deallocated.

关于c++ - valgrind memcheck 是否支持检查 mmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15334191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com