簡體   English   中英

Valgrind +-泄漏檢查->不泄漏摘要

[英]Valgrind + --leak-check -> not leak summary

我有一個調用extern庫(log4cplus)的多線程程序。
當我記錄某些內容時,內存消耗會增加,但絕不會減少。

我使用--leak-check = yes選項運行valgrind。 我得到:

HEAP SUMMARY
    ==413==     in use at exit: 2,944,909 bytes in 23,429 blocks
    ==413==   total heap usage: 99,472,873 allocs, 99,449,444 frees, 8,049,350,322 bytes allocated

但是我沒有任何泄漏內存摘要。

  1. 這是否意味着仍可以訪問2,944,909字節,因此在停止進程時將其釋放?
  2. 如何知道罪魁禍首是我的程序還是lib?

如下面的建議,我添加了一個選項以獲取更多詳細信息。 我有很長的報告。 這是摘錄:

==18326== 6,480 bytes in 15 blocks are still reachable in loss record 3,959 of 4,015
==18326==    at 0x482B728: operator new(unsigned int) (vg_replace_malloc.c:328)
==18326==    by 0x15F04F8: __gnu_cxx::new_allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent>::allocate(unsigned int, void const*) (new_allocator.h:104)
==18326==    by 0x15EFB7F: std::allocator_traits<std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent> >::allocate(std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent>&, unsigned int) (alloc_traits.h:416)
==18326==    by 0x15EF320: std::_Deque_base<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent> >::_M_allocate_node() (stl_deque.h:600)
==18326==    by 0x15EE678: std::_Deque_base<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent> >::_M_create_nodes(Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent**, Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent**) (stl_deque.h:725)
==18326==    by 0x15ED5AF: std::_Deque_base<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent> >::_M_initialize_map(unsigned int) (stl_deque.h:699)
==18326==    by 0x15EBFEF: std::_Deque_base<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent> >::_Deque_base() (stl_deque.h:490)
==18326==    by 0x15EB045: std::deque<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, std::allocator<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent> >::deque() (stl_deque.h:884)
==18326==    by 0x15ECF6C: Koin::Common::Containers::StdQueueWrapper<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, true>::clear() (StdQueueWrapper.h:57)
==18326==    by 0x15EB880: Koin::Common::Containers::StdQueueWrapper<Koin::Common::Logging::Log4Cplus::InternalLoggingWrapperEvent, true>::pop_front() (StdQueueWrapper.h:36)
==18326==    by 0x15E9D62: Koin::Common::Logging::Log4Cplus::Log4CplusLoggerProcessor::Execute() (Log4CplusLoggerProcessor.cpp:63)
==18326==    by 0x15F1617: void std::__invoke_impl<void, void (Koin::Common::Logging::Log4Cplus::Log4CplusLoggerProcessor::* const&)(), Koin::Common::Logging::Log4Cplus::Log4CplusLoggerProcessor*>(std::__invoke_memfun_deref, void (Koin::Common::Logging::Log4Cplus::Log4CplusLoggerProcessor::* const&)(), Koin::Common::Logging::Log4Cplus::Log4CplusLoggerProcess  or*&&) (functional:235)
  1. 使用valgrind標志--leak-check=full --show-reachable=yes這將轉儲所有可訪問內存的位置,您需要從那里取出它來--leak-check=full --show-reachable=yes誰應該負責處置該內存。

作為此程序的示例:

#include <stdlib.h>

char *var;

void myfunc(char *c)
{
    var = c;
}
int main(int argc, char *argv[])
{
   myfunc(malloc(4));

    return 0;
}

$ valgrind   --leak-check=full --show-reachable=yes ./a.out 
==21480== Memcheck, a memory error detector
==21480== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==21480== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==21480== Command: ./a.out
==21480== 
==21480== 
==21480== HEAP SUMMARY:
==21480==     in use at exit: 4 bytes in 1 blocks
==21480==   total heap usage: 1 allocs, 0 frees, 4 bytes allocated
==21480== 
==21480== 4 bytes in 1 blocks are still reachable in loss record 1 of 1
==21480==    at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==21480==    by 0x4004DC: main (t.c:6)
==21480== 
==21480== LEAK SUMMARY:
==21480==    definitely lost: 0 bytes in 0 blocks
==21480==    indirectly lost: 0 bytes in 0 blocks
==21480==      possibly lost: 0 bytes in 0 blocks
==21480==    still reachable: 4 bytes in 1 blocks
==21480==         suppressed: 0 bytes in 0 blocks
==21480== 
==21480== For counts of detected and suppressed errors, rerun with: -v
==21480== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6)

在這里valgrind將向您顯示main()中的第11行分配了4個字節的內存,並且您需要通過myfunc()等來跟蹤此分配的內存最終到達的位置,並說明誰應該取消分配此內存。

當你正在使用log4cplus,確保你去初始化,如提及的例子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM