Boost C++ Libraries: Ticket #9830: memory leak in time_duration https://svn.boost.org/trac10/ticket/9830 <p> Hi folks, this is a leak i've found compiling this very single line: boost::posix_time::time_duration td(1,0,0,0); cout &lt;&lt; td; </p> <p> valgrind reports the following leak: ==16902== 25 bytes in 1 blocks are possibly lost in loss record 21 of 29 ==16902== at 0x40290AC: operator new(unsigned int) (vg_replace_malloc.c:313) ==16902== by 0x455BB54: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator&lt;char&gt; const&amp;) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19) ==16902== by 0x455CC72: std::string::_Rep::_M_clone(std::allocator&lt;char&gt; const&amp;, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19) ==16902== by 0x455CD10: std::string::reserve(unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19) ==16902== by 0x455CF8C: std::string::append(char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19) ==16902== by 0x8079DE9: boost::date_time::time_facet&lt;boost::posix_time::ptime, char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::time_facet(unsigned int) (in /home/marcos/release/sandbox/chutaygol) ==16902== by 0x8084086: std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; boost::posix_time::operator&lt;&lt; &lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, boost::posix_time::time_duration const&amp;) </p> <p> I hope you find a bug with the help of my report Marcos Mayorga </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9830 Trac 1.4.3 anonymous Thu, 10 Apr 2014 14:56:48 GMT <link>https://svn.boost.org/trac10/ticket/9830#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9830#comment:1</guid> <description> <p> Valgrind's backtrace of the leak: </p> <pre class="wiki">==17499== at 0x40290AC: operator new(unsigned int) (vg_replace_malloc.c:313) ==17499== by 0x465A9E4: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator&lt;char&gt; const&amp;) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19) ==17499== by 0x43156DB: char* std::string::_S_construct&lt;char const*&gt;(char const*, char const*, std::allocator&lt;char&gt; const&amp;, std::forward_iterator_tag) (in /usr/lib/libjsoncpp.so.0.6.0) ==17499== by 0x465CF8F: std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(char const*, std::allocator&lt;char&gt; const&amp;) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19) ==17499== by 0x80ABF31: boost::date_time::date_generator_formatter&lt;boost::gregorian::date, char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::date_generator_formatter() (date_generator_formatter.hpp:73) ==17499== by 0x80A5815: boost::date_time::time_facet&lt;boost::posix_time::ptime, char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::time_facet(unsigned int) (time_facet.hpp:249) ==17499== by 0x80A05F8: std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; boost::posix_time::operator&lt;&lt; &lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, boost::posix_time::time_duration const&amp;) (posix_time_io.hpp:193) </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 10 Apr 2014 15:10:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9830#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9830#comment:2</guid> <description> <p> probably line 193 of posix_time_io.hpp </p> <pre class="wiki">188 //instantiate a custom facet for dealing with times since the user 189 //has not put one in the stream so far. This is for efficiency 190 //since we would always need to reconstruct for every time period 191 //if the locale did not already exist. Of course this will be overridden 192 //if the user imbues as some later point. 193 custom_ptime_facet* f = new custom_ptime_facet(); 194 std::locale l = std::locale(os.getloc(), f); 195 os.imbue(l); 196 f-&gt;put(oitr, os, os.fill(), td); </pre> </description> <category>Ticket</category> </item> </channel> </rss>