启用内存泄漏的valgrind输出如下所示 从堆栈跟踪中,如何找到内存泄漏的位置? 它可能是libpq.so吗?
==8909==
==8909== HEAP SUMMARY:
==8909== in use at exit: 373,468 bytes in 2,997 blocks
==8909== total heap usage: 30,367 allocs, 27,370 frees, 5,535,985 bytes allocated
==8909==
==8909== 123,640 (11,000 direct, 112,640 indirect) bytes in 55 blocks are definitely lost in loss record 290 of 291
==8909== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8909== by 0x52919F3: PQmakeEmptyPGresult (in /usr/lib/libpq.so.5.4)
==8909== by 0x529BA40: ??? (in /usr/lib/libpq.so.5.4)
==8909== by 0x5293767: PQgetResult (in /usr/lib/libpq.so.5.4)
==8909== by 0x5293AB7: ??? (in /usr/lib/libpq.so.5.4)
==8909== by 0x416B29: readTable() (thread.cpp:366)
==8909== by 0x40D018: _ZNSt12_Bind_simpleIFPFvvEvEE9_M_invokeIIEEEvSt12_Index_tupleIIXspT_EEE (functional:1732)
==8909== by 0x40CC94: std::_Bind_simple<void (*()())()>::operator()() (functional:1720)
==8909== by 0x40CB55: std::thread::_Impl<std::_Bind_simple<void (*()())()> >::_M_run() (thread:115)
==8909== by 0x5560ABF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17)
==8909== by 0x65B9E99: start_thread (pthread_create.c:308)
==8909== by 0x5ABB3FC: clone (clone.S:112)
==8909==
==8909== 123,640 (11,000 direct, 112,640 indirect) bytes in 55 blocks are definitely lost in loss record 291 of 291
==8909== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8909== by 0x52919F3: PQmakeEmptyPGresult (in /usr/lib/libpq.so.5.4)
==8909== by 0x529BA40: ??? (in /usr/lib/libpq.so.5.4)
==8909== by 0x5293767: PQgetResult (in /usr/lib/libpq.so.5.4)
==8909== by 0x5293AB7: ??? (in /usr/lib/libpq.so.5.4)
==8909== by 0x416E55: readTable() (thread.cpp:405)
==8909== by 0x40D018: _ZNSt12_Bind_simpleIFPFvvEvEE9_M_invokeIIEEEvSt12_Index_tupleIIXspT_EEE (functional:1732)
==8909== by 0x40CC94: std::_Bind_simple<void (*()())()>::operator()() (functional:1720)
==8909== by 0x40CB55: std::thread::_Impl<std::_Bind_simple<void (*()())()> >::_M_run() (thread:115)
==8909== by 0x5560ABF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17)
==8909== by 0x65B9E99: start_thread (pthread_create.c:308)
==8909== by 0x5ABB3FC: clone (clone.S:112)
==8909==
==8909== LEAK SUMMARY:
==8909== definitely lost: 22,000 bytes in 110 blocks
==8909== indirectly lost: 225,280 bytes in 110 blocks
==8909== possibly lost: 0 bytes in 0 blocks
==8909== still reachable: 126,188 bytes in 2,777 blocks
==8909== suppressed: 0 bytes in 0 blocks
==8909== Reachable blocks (those to which a pointer was found) are not shown.
==8909== To see them, rerun with: --leak-check=full --show-reachable=yes
==8909==
==8909== For counts of detected and suppressed errors, rerun with: -v
==8909== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2 from 2)
提前感谢您的帮助。
答案 0 :(得分:0)
尝试attaching gdb to valgrind,然后将断点设置为您认为可能发生泄漏的位置。然后,运行gsub('mass \\|([0-9]* [A-Za-z]*).*', '\\1', alt)
[1] "36 grams"
以查看是否有任何丢失。据我所知,你不能为丢失内存设置一个断点,但是你可以直接执行你的程序。