繁体   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