|
From: Peng Yu <pen...@gm...> - 2011-09-07 14:53:41
|
On Wed, Sep 7, 2011 at 9:39 AM, Tom Hughes <to...@co...> wrote: > On 07/09/11 15:37, Peng Yu wrote: > >> I think that there is problem between std::string and valgrind. I >> changed the the std:string used inside std::runtime_error and get a >> new class ValgrindRuntimeError. Using this new class, the possibly >> lost is gone. > > Please read the FAQ entry about std::string and memory leaks: > > http://valgrind.org/docs/manual/faq.html#faq.reports Using malloc, doesn't help in this case. See below. /tmp$ cat main.cpp #include <stdexcept> int main() { throw std::runtime_error("xx"); } /tmp$ g++ --version i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. /tmp$ export GLIBCXX_FORCE_NEW /tmp$ g++ main.cpp /tmp$ valgrind ./a.out ==42321== Memcheck, a memory error detector ==42321== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==42321== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==42321== Command: ./a.out ==42321== --42321-- ./a.out: --42321-- dSYM directory is missing; consider using --dsymutil=yes terminate called after throwing an instance of 'std::runtime_error' what(): xx ==42321== ==42321== Process terminating with default action of signal 6 (SIGABRT) ==42321== at 0x1001500B6: __kill (in /usr/lib/libSystem.B.dylib) ==42321== by 0x10006F5D1: __gnu_cxx::__verbose_terminate_handler() (in /usr/lib/libstdc++.6.0.9.dylib) ==42321== by 0x10006DAE0: __cxxabiv1::__terminate(void (*)()) (in /usr/lib/libstdc++.6.0.9.dylib) ==42321== by 0x10006DB15: std::terminate() (in /usr/lib/libstdc++.6.0.9.dylib) ==42321== by 0x10006DBFB: __cxa_throw (in /usr/lib/libstdc++.6.0.9.dylib) ==42321== by 0x100000DF7: main (in ./a.out) ==42321== ==42321== HEAP SUMMARY: ==42321== in use at exit: 259 bytes in 4 blocks ==42321== total heap usage: 5 allocs, 1 frees, 282 bytes allocated ==42321== ==42321== LEAK SUMMARY: ==42321== definitely lost: 0 bytes in 0 blocks ==42321== indirectly lost: 0 bytes in 0 blocks ==42321== possibly lost: 27 bytes in 1 blocks ==42321== still reachable: 232 bytes in 3 blocks ==42321== suppressed: 0 bytes in 0 blocks ==42321== Rerun with --leak-check=full to see details of leaked memory ==42321== ==42321== For counts of detected and suppressed errors, rerun with: -v ==42321== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Abort trap -- Regards, Peng |