[date_time] memory leak?

Hello, Code: #include <iostream> #include <boost/date_time/posix_time/posix_time.hpp> int main() { std::cout << boost::posix_time::microsec_clock::local_time() << std::endl; return 0; } Running through valgrind yields this: ==5963== ==5963== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 2) ==5963== malloc/free: in use at exit: 1,595 bytes in 27 blocks. ==5963== malloc/free: 63 allocs, 36 frees, 7,878 bytes allocated. ==5963== For counts of detected errors, rerun with: -v ==5963== searching for pointers to 27 not-freed blocks. ==5963== checked 173,784 bytes. ==5963== ==5963== 619 bytes in 20 blocks are possibly lost in loss record 7 of 7 ==5963== at 0x4A06FFC: operator new(unsigned long) (vg_replace_malloc.c:230) ==5963== by 0x352C0A0140: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.12) ==5963== by 0x352C0A0D64: (within /usr/lib64/libstdc++.so.6.0.12) ==5963== by 0x352C0A0F01: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.12) ==5963== by 0x408AD7: boost::date_time::date_generator_formatter<boost::gregorian::date, char, std::ostreambuf_iterator<char, std::char_traits<char> > >::date_generator_formatter() (in /home/bma/c++/boost_dt) ==5963== by 0x407B20: boost::date_time::time_facet<boost::posix_time::ptime, char, std::ostreambuf_iterator<char, std::char_traits<char> > >::time_facet(unsigned long) (in /home/bma/c++/boost_dt) ==5963== by 0x40494B: std::basic_ostream<char, std::char_traits<char> >& boost::posix_time::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, boost::posix_time::ptime const&) (in /home/bma/c++/boost_dt) ==5963== by 0x402AA0: main (in /home/bma/c++/boost_dt) ==5963== ==5963== LEAK SUMMARY: ==5963== definitely lost: 0 bytes in 0 blocks. ==5963== possibly lost: 619 bytes in 20 blocks. ==5963== still reachable: 976 bytes in 7 blocks. ==5963== suppressed: 0 bytes in 0 blocks. ==5963== Reachable blocks (those to which a pointer was found) are not shown. ==5963== To see them, rerun with: --leak-check=full --show-reachable=yes This is boost-1.37.0-9.fc11 (fedora core 11), gcc 4.4.1, x86-64 platform. Is it memory leak? Best regards, bma. -- Bartosz Marcinkiewicz tel. (+48) 516 034 243 e-mail: bma@epcon.pl, bartosz.marcinkiewicz@epcon.pl EPCON Sp. z o.o. www.epcon.pl adres: 53-407 Wrocław, ul. Gajowicka 114/116 tel. (+48) 71 361 75 55 ext.36 fax (+48) 71 361 74 44 NIP PL 899-24-92-498 KRS 0000190187 REGON 932963731 Kapitał zakładowy: 500 000 PLN

Bartosz Marcinkiewicz wrote:
#include <iostream> #include <boost/date_time/posix_time/posix_time.hpp>
int main() { std::cout << boost::posix_time::microsec_clock::local_time() << std::endl; return 0; }
Running through valgrind yields this: [snip] This is boost-1.37.0-9.fc11 (fedora core 11), gcc 4.4.1, x86-64 platform.
valgrind did not find any problems with this setup: boost v1.41 x86-64 Red Hat Enterprise Linux Server release 5.4 (Tikanga) gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46) --> Mika Heiskanen

Bartosz Marcinkiewicz wrote:
Hello,
Code:
#include <iostream> #include <boost/date_time/posix_time/posix_time.hpp>
int main() { std::cout << boost::posix_time::microsec_clock::local_time() << std::endl; return 0; }
Running through valgrind yields this:
With valgrind --leak-check=full I get a similar report.
==5963== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 2) ==5963== malloc/free: in use at exit: 1,595 bytes in 27 blocks. ==5963== malloc/free: 63 allocs, 36 frees, 7,878 bytes allocated. ==5963== For counts of detected errors, rerun with: -v ==5963== searching for pointers to 27 not-freed blocks. ==5963== checked 173,784 bytes. ==5963== ==5963== 619 bytes in 20 blocks are possibly lost in loss record 7 of 7 ==5963== at 0x4A06FFC: operator new(unsigned long) (vg_replace_malloc.c:230) ==5963== by 0x352C0A0140: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.12) ==5963== by 0x352C0A0D64: (within /usr/lib64/libstdc++.so.6.0.12) ==5963== by 0x352C0A0F01: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.12) ==5963== by 0x408AD7: boost::date_time::date_generator_formatter<boost::gregorian::date, char, std::ostreambuf_iterator<char, std::char_traits<char> > >::date_generator_formatter() (in /home/bma/c++/boost_dt) ==5963== by 0x407B20: boost::date_time::time_facet<boost::posix_time::ptime, char, std::ostreambuf_iterator<char, std::char_traits<char> > >::time_facet(unsigned long) (in /home/bma/c++/boost_dt) ==5963== by 0x40494B: std::basic_ostream<char, std::char_traits<char> >& boost::posix_time::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, boost::posix_time::ptime const&) (in /home/bma/c++/boost_dt) ==5963== by 0x402AA0: main (in /home/bma/c++/boost_dt) ==5963== ==5963== LEAK SUMMARY: ==5963== definitely lost: 0 bytes in 0 blocks. ==5963== possibly lost: 619 bytes in 20 blocks. ==5963== still reachable: 976 bytes in 7 blocks. ==5963== suppressed: 0 bytes in 0 blocks. ==5963== Reachable blocks (those to which a pointer was found) are not shown. ==5963== To see them, rerun with: --leak-check=full --show-reachable=yes
This is boost-1.37.0-9.fc11 (fedora core 11), gcc 4.4.1, x86-64 platform. Is it memory leak?
Best regards, bma.
--> Mika Heiskanen

Hello,
#include <iostream> #include <boost/date_time/posix_time/posix_time.hpp>
int main() { std::cout << boost::posix_time::microsec_clock::local_time() << std::endl; return 0; }
Generally boost::posix_time imbues its own facet into the locale std::cout steam. So this facet remains reachable because AFAIK std::cout is not destroyed at all. So if you do: std::cout.imbue(std::locale::classic()); Before return, no "leaks" would be at all. Same as if you would write to any destroyable stream like std::ostringstream; std::ostringstream tmp; tmp << boost::posix_time::microsec_clock::local_time(); std::cout << tmp.str() << std::endl; So it is rather C++ design question why std::cout does not destroy its own locale. Artyom
participants (3)
-
Artyom
-
Bartosz Marcinkiewicz
-
Mika Heiskanen