2013-03-11 32 views
6

Tôi đang cố gắng valgrind để phát hiện rò rỉ bộ nhớ. Nó hoạt động tốt trên heap leak (tức là cấp phát bộ nhớ từ malloc hoặc mới). Tuy nhiên, nó hỗ trợ kiểm tra mmap rò rỉ trong linux?Không hỗ trợ memcheck valgrind kiểm tra mmap

Cảm ơn Chang

Trả lời

6

Không trực tiếp, nó rất khó để gỡ lỗi, hãy nhìn vào 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ác vấn đề liên quan