如何使用 valgrind 3.7.0 打印内存泄漏根本原因的行号

How to print line number for the root cause of memory leak using valgrind 3.7.0?

本文关键字:泄漏 内存 valgrind 何使用 打印      更新时间:2023-10-16

输出格式显示堆栈,因此很难找到根本原因。

 ==21663== Invalid read of size 4
==21663==    at 0x4448117: iurcall_init_rlmgt_IsAllAlcapSuccess(Iurcall_Init_CallCtx_t*) (iurcall_init_rlmgt_p.cc:6319)
==21663==    by 0x47D98DD: iurcall_init_rlmgt_IsAllAlcapSuccess_Test_return_1_when_edchMacD_flow_ctx_not_exist_and_alcapEstablish_is_FALSE_Test::TestBody() (iurcall_init_rlmgt_p_test.cc:373)
==21663==    by 0x8BCAB27: testing::Test::Run() (gmock-gtest-all.cc:3436)
==21663==    by 0x8BD1966: testing::internal::TestInfoImpl::Run() (gmock-gtest-all.cc:3655)
==21663==    by 0x8BD1AA8: testing::TestCase::Run() (gmock-gtest-all.cc:3761)
==21663==    by 0x8BD1D96: testing::internal::UnitTestImpl::RunAllTests() (gmock-gtest-all.cc:5365)
==21663==    by 0x8BD1F21: testing::UnitTest::Run() (gmock-gtest-all.cc:5028)
==21663==    by 0x4820149: Gtest_initialisation(int, char**) (iurcall_init_gtest_main.cc:49)
==21663==    by 0x808E500: main (bosinit_config_template.h:439)
==21663==  Address 0xa8190e4 is 44 bytes inside a block of size 56 free'd

这个瓦尔格林德输出看起来不完整。它应该类似于在这个问题中,第二个调用堆栈在Address 0xa8190e4 is 44 bytes inside a block of size 56 free'd之后打印。

此调用堆栈是问题的根本原因。这不是内存泄漏。您正在尝试使用已解除分配的对象。第二个调用堆栈是释放对象的位置,第一个调用堆栈是使用它的位置。