[so] Re: valgrind
Andrei Ciuca
andrei.ciuca at gmail.com
Thu Nov 1 12:28:50 EET 2007
Salut, ai dreptate.
In timp ce scoteam cod, am observat urmatoarea chestie :
Daca rulez codul asta :
int main()
{
cout << "\n> ";
string line;
getline(cin, line);
command_t* root = NULL;
parse_line(line.c_str(), &root);
free_parse_memory();
exit(0);
}
Da outputul asta :
==2981== Memcheck, a memory error detector.
==2981== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==2981== Using LibVEX rev 1606, a library for dynamic binary translation.
==2981== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==2981== Using valgrind-3.2.0-Debian, a dynamic binary instrumentation
framework.
==2981== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==2981== For more details, rerun with: -v
==2981==
==2981== My PID = 2981, parent PID = 2259. Prog and args are:
==2981== ./tema1
==2981==
--2981-- DWARF2 CFI reader: unhandled CFI instruction 0:50
--2981-- DWARF2 CFI reader: unhandled CFI instruction 0:50
==2981==
==2981== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)
==2981== malloc/free: in use at exit: 17 bytes in 1 blocks.
==2981== malloc/free: 12 allocs, 11 frees, 209 bytes allocated.
==2981== For counts of detected errors, rerun with: -v
==2981== searching for pointers to 1 not-freed blocks.
==2981== checked 108,104 bytes.
==2981==
==2981== 17 bytes in 1 blocks are possibly lost in loss record 1 of 1
==2981== at 0x401B8C7: operator new(unsigned) (vg_replace_malloc.c:163)
==2981== by 0x40B0C6A: std::string::_Rep::_S_create(unsigned, unsigned,
std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.8)
==2981== by 0x40B1BE9: std::string::_Rep::_M_clone(std::allocator<char>
const&, unsigned) (in /usr/lib/libstdc++.so.6.0.8)
==2981== by 0x40B35E7: std::string::reserve(unsigned) (in
/usr/lib/libstdc++.so.6.0.8)
==2981== by 0x4089126: std::basic_istream<char, std::char_traits<char> >&
std::getline<char, std::char_traits<char>, std::allocator<char>
>(std::basic_istream<char, std::char_traits<char> >&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >&,
char) (in /usr/lib/libstdc++.so.6.0.8)
==2981== by 0x40A2178: std::basic_istream<char, std::char_traits<char> >&
std::getline<char, std::char_traits<char>, std::allocator<char>
>(std::basic_istream<char, std::char_traits<char> >&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (in
/usr/lib/libstdc++.so.6.0.8)
==2981== by 0x80493E9: main (tema1.cpp:875)
==2981==
==2981== LEAK SUMMARY:
==2981== definitely lost: 0 bytes in 0 blocks.
==2981== possibly lost: 17 bytes in 1 blocks.
==2981== still reachable: 0 bytes in 0 blocks.
==2981== suppressed: 0 bytes in 0 blocks.
Daca rulez codul asta (diferenta este ca in loc sa dau "exit(0)" dau "return
0" ):
int main()
{
cout << "\n> ";
string line;
getline(cin, line);
command_t* root = NULL;
parse_line(line.c_str(), &root);
free_parse_memory();
return 0;
}
atunci valgrind spune ca totul e ok - "no memory leaks possible".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cursuri.cs.pub.ro/pipermail/so/attachments/20071101/4803433b/attachment-0001.htm
More information about the so
mailing list