I'm trying to track down some mysterious crashes that seem to be memory-related thus far. So, I've started using Valgrind to get it done. I've never used it before, but the first run gave me some good information. Today I had a chance to run it again (the circumstance in which we see a crash isn't reproducible) and the output was decidedly less useful.
==11831==
==11831== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==11831== Bad permissions for mapped region at address 0x75EAB8
==11831== at 0x75EAB8: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==11831==
==11831== HEAP SUMMARY:
==11831== in use at exit: 3,611,867 bytes in 12,934 blocks
==11831== total heap usage: 15,871 allocs, 2,937 frees, 26,483,142 bytes allocated
==11831==
==11831== LEAK SUMMARY:
==11831== definitely lost: 0 bytes in 0 blocks
==11831== indirectly lost: 0 bytes in 0 blocks
==11831== possibly lost: 206,203 bytes in 7,146 blocks
==11831== still reachable: 3,405,664 bytes in 5,788 blocks
==11831== suppressed: 0 bytes in 0 blocks
==11831== Rerun with --leak-check=full to see details of leaked memory
==11831==
==11831== For counts of detected and suppressed errors, rerun with: -v
==11831== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
So, I ran it again with --leak-check=full
and it did give me more:
==13764==
==13764== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==13764== Bad permissions for mapped region at address 0x75EAB8
==13764== at 0x75EAB8: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764== by 0x75EAB7: ??? (in /usr/local/bin/test-app.V1.88)
==13764==
==13764== HEAP SUMMARY:
==13764== in use at exit: 3,611,867 bytes in 12,934 blocks
==13764== total heap usage: 15,871 allocs, 2,937 frees, 26,483,154 bytes allocated
==13764==
==13764== 26 bytes in 1 blocks are possibly lost in loss record 5 of 343
==13764== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13764== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED0C79: std::string::_M_mutate(unsigned long, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED0E1B: std::string::_M_replace_safe(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4D48B3: abc::load_config_file(std::string) (abc_read_config_file.cpp:46)
==13764== by 0x4C0A3A: AppStartup(int, char**, char const*) (AppBase.cpp:58)
==13764== by 0x49BFC1: main (App.cpp:54)
==13764==
==13764== 28 bytes in 1 blocks are possibly lost in loss record 6 of 343
==13764== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13764== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4FCB74: __static_initialization_and_destruction_0(int, int) (xyzLib.cc:46)
==13764== by 0x4FCD12: _GLOBAL__sub_I_xyzLib.cc (xyzLib.cc:2179)
==13764== by 0x52280C: __libc_csu_init (in /usr/local/bin/test-app.V1.88)
==13764== by 0x58826FF: (below main) (libc-start.c:185)
==13764==
==13764== 28 bytes in 1 blocks are possibly lost in loss record 7 of 343
==13764== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13764== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED22B4: char* std::string::_S_construct<char*>(char*, char*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED2414: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED2441: std::string::substr(unsigned long, unsigned long) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x500E27: XyzParameter::getField(std::string&, char const*, std::string const&, unsigned long&, bool) (xyzMessageCodec.hh:1186)
==13764== by 0x500FBB: XyzParameter::getFields(std::vector<std::string, std::allocator<std::string> >&, int, std::string const&, bool) (xyzMessageCodec.hh:1219)
==13764== by 0x5021F3: XyzParameter::getPositionsList(std::string const&) (xyzMessageCodec.hh:1414)
==13764== by 0x4FAF0B: Xyz::XyzLib::MessageHandler::handleOpenPositionsResponse(void*) (xyzLib.cc:1854)
==13764== by 0x4F8F08: Xyz::XyzLib::MessageHandler::handleXyzMsg(void*) (xyzLib.cc:1444)
==13764== by 0x4F7CCC: Xyz::XyzLib::MessageHandler::onMsg(Xyz::Xyz::XyzMessage*) (xyzLib.cc:1211)
==13764== by 0x51101D: Xyz::Xyz::XyzSession::processNextMsg() (xyzSession.cc:270)
==13764==
==13764== 29 bytes in 1 blocks are possibly lost in loss record 8 of 343
==13764== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13764== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4A62CE: __static_initialization_and_destruction_0(int, int) (Distributor.h:190)
==13764== by 0x4A659F: _GLOBAL__sub_I_abc.cpp (abc.cpp:522)
==13764== by 0x52280C: __libc_csu_init (in /usr/local/bin/test-app.V1.88)
==13764== by 0x58826FF: (below main) (libc-start.c:185)
==13764==
==13764== 29 bytes in 1 blocks are possibly lost in loss record 9 of 343
==13764== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13764== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==13764== by 0x4A6311: __static_initialization_and_destruction_0(int, int) (Distributor.h:190)
==13764== by 0x4A659F: _GLOBAL__sub_I_abc.cpp (abc.cpp:522)
==13764== by 0x52280C: __libc_csu_init (in /usr/local/bin/test-app.V1.88)
==13764== by 0x58826FF: (below main) (libc-start.c:185)
And on it goes for another 14,000 lines and a few PID's.
My question is: what exactly is this reporting? The last time I ran valgrind on an app crashing like this, I was pointed squarely at the destructor of a class, specifically of a std::string
data member of that class. This time, however, valgrind only has question marks for me and a whole lot more dealing with the new
operator from std::string
. I'm genuinely unaware how one might proceed with this information to arrive at some sort of conclusion and fix a bug or four.
EDIT Here are the specific lines valgrind is suspicious of:
app_params.tracked_symbol="a";
const std::string XyzLib::LANGUAGE_ID = "C++";
The next two are a return
statement and the closing brace of a class. It continues like that for quite a few instances of valgrind's concern (closing braces of the several classes).