Boost C++ Libraries: Ticket #13186: Memory leak in serialization 1.65 https://svn.boost.org/trac10/ticket/13186 <p> Hi, we are seeing a seg fault seemingly caused by a difference between boost serialization 1.64 and 1.65 (no problems in 1.64 or any other boost we are currently testing &gt;1.48 as part of Chaste computational physiology library). Unfortunately the minimal failing test is a bit complicated I'm afraid, this only seems to show up with a hierarchy of serialization classes. </p> <p> I've attached valgrind memory testing output which should hopefully give all the clues needed to track it down: </p> <pre class="wiki">==20488== Memcheck, a memory error detector ==20488== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==20488== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==20488== Command: mesh/build/debug_hostconfig,boost=1-65/TestNodesOnlyMeshRunner -malloc_debug -malloc_dump -memory_info ==20488== Parent PID: 20487 ==20488== ==20488== Invalid read of size 8 ==20488== at 0x7E55025: boost::serialization::typeid_system::extended_type_info_typeid_0::type_unregister() (in /home/robert/boost_1_65/lib/libboost_serialization.so.1.65.0) ==20488== by 0x4756E6: boost::serialization::extended_type_info_typeid&lt;AbstractTetrahedralMesh&lt;3u, 3u&gt; &gt;::~extended_type_info_typeid() (extended_type_info_typeid.hpp:96) ==20488== by 0x474F02: boost::serialization::singleton&lt;boost::serialization::extended_type_info_typeid&lt;AbstractTetrahedralMesh&lt;3u, 3u&gt; &gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (in /home/garmir/workspace/Chaste/mesh/build/debug_hostconfig,boost=1-65/TestNodesOnlyMeshRunner) ==20488== by 0x9E2E1A8: __run_exit_handlers (exit.c:82) ==20488== by 0x9E2E1F4: exit (exit.c:104) ==20488== by 0x9E13F4B: (below main) (libc-start.c:321) ==20488== Address 0x17bd1740 is 32 bytes inside a block of size 40 free'd ==20488== at 0x4C2C2BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==20488== by 0x7E55572: boost::serialization::singleton&lt;std::multiset&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (in /home/robert/boost_1_65/lib/libboost_serialization.so.1.65.0) ==20488== by 0x9E2E539: __cxa_finalize (cxa_finalize.c:56) ==20488== by 0x7E4D402: ??? (in /home/robert/boost_1_65/lib/libboost_serialization.so.1.65.0) ==20488== by 0x40108D9: _dl_fini (dl-fini.c:252) ==20488== by 0x9E2E1A8: __run_exit_handlers (exit.c:82) ==20488== by 0x9E2E1F4: exit (exit.c:104) ==20488== by 0x9E13F4B: (below main) (libc-start.c:321) ==20488== ==20488== Invalid read of size 8 ==20488== at 0x7E55036: boost::serialization::typeid_system::extended_type_info_typeid_0::type_unregister() (in /home/robert/boost_1_65/lib/libboost_serialization.so.1.65.0) ==20488== by 0x4756E6: boost::serialization::extended_type_info_typeid&lt;AbstractTetrahedralMesh&lt;3u, 3u&gt; &gt;::~extended_type_info_typeid() (extended_type_info_typeid.hpp:96) ==20488== by 0x474F02: boost::serialization::singleton&lt;boost::serialization::extended_type_info_typeid&lt;AbstractTetrahedralMesh&lt;3u, 3u&gt; &gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (in /home/garmir/workspace/Chaste/mesh/build/debug_hostconfig,boost=1-65/TestNodesOnlyMeshRunner) ==20488== by 0x9E2E1A8: __run_exit_handlers (exit.c:82) ==20488== by 0x9E2E1F4: exit (exit.c:104) ==20488== by 0x9E13F4B: (below main) (libc-start.c:321) ==20488== Address 0x17bd1738 is 24 bytes inside a block of size 40 free'd ==20488== at 0x4C2C2BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==20488== by 0x7E55572: boost::serialization::singleton&lt;std::multiset&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*, boost::serialization::typeid_system::type_compare, std::allocator&lt;boost::serialization::typeid_system::extended_type_info_typeid_0 const*&gt; &gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (in /home/robert/boost_1_65/lib/libboost_serialization.so.1.65.0) ==20488== by 0x9E2E539: __cxa_finalize (cxa_finalize.c:56) ==20488== by 0x7E4D402: ??? (in /home/robert/boost_1_65/lib/libboost_serialization.so.1.65.0) ==20488== by 0x40108D9: _dl_fini (dl-fini.c:252) ==20488== by 0x9E2E1A8: __run_exit_handlers (exit.c:82) ==20488== by 0x9E2E1F4: exit (exit.c:104) ==20488== by 0x9E13F4B: (below main) (libc-start.c:321) </pre><p> Incidentally, the consequences are exactly the same as a problem that existed in boost 1.46 and was fixed in 1.48. I don't know if the underlying problem is related. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13186 Trac 1.4.3 gary.mirams@… Fri, 01 Sep 2017 10:26:32 GMT attachment set https://svn.boost.org/trac10/ticket/13186 https://svn.boost.org/trac10/ticket/13186 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">memory_output.txt</span> </li> </ul> <p> full valgrind output (ignore PETSc stuff - that always happens!) </p> Ticket gary.mirams@… Fri, 01 Sep 2017 10:28:33 GMT <link>https://svn.boost.org/trac10/ticket/13186#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:1</guid> <description> <p> This was submitted by Gary Mirams &lt;gary.mirams@…&gt; I failed to log in to trac properly, sorry </p> </description> <category>Ticket</category> </item> <item> <author>Gary Mirams <gary.mirams@…></author> <pubDate>Fri, 01 Sep 2017 11:04:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:2</guid> <description> <p> Perhaps related to these changes: <a class="ext-link" href="https://github.com/boostorg/serialization/commit/b0a794da38b52c8ae0f8155cf3bb30321cf67f00"><span class="icon">​</span>https://github.com/boostorg/serialization/commit/b0a794da38b52c8ae0f8155cf3bb30321cf67f00</a> ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 27 Sep 2017 05:24:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:3</guid> <description> <p> We are also getting the segmentation fault (double free or corruption (fasttop): 0x00000000007e0730 ) </p> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5" title="#5: Bugs: shared_ptr and self-owning objects (closed: Fixed)">#5</a> 0x00007ffff59d1d14 in boost::serialization::extended_type_info::key_unregister() const () </p> <blockquote> <p> from glnxa64/libmwboost_serialization.so.1.65.0 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6" title="#6: Bugs: tie in utility.hpp and tuple.hpp clash. (closed: Duplicate)">#6</a> 0x000000000050ebde in boost::serialization::extended_type_info_typeid&lt;Message&gt;::~extended_type_info_typeid (this=0x7cbd80, <span class="underline">in_chrg=&lt;optimized out&gt;) </span></p> <blockquote> <p> at boost/serialization/extended_type_info_typeid.hpp:128 </p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7" title="#7: Bugs: g++ 2.96 requires NO_STRINGSTREAM (closed: Fixed)">#7</a> 0x000000000050da6a in boost::serialization::singleton&lt;boost::serialization::extended_type_info_typeid&lt;Message&gt; &gt;::get_instance()::singleton_wrapper::~singleton_wrapper() (this=0x7cbd80, </p> <blockquote> <p> <span class="underline">in_chrg=&lt;optimized out&gt;) at /boost/include/boost/serialization/singleton.hpp:150 </span></p> </blockquote> <p> <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8" title="#8: Bugs: prop in undirected graph + out_edges (closed: Works For Me)">#8</a> 0x00007ffff4841b29 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9" title="#9: Bugs: config_info ambiguity error (closed: Invalid)">#9</a> 0x00007ffff4841b75 in exit () from /lib/x86_64-linux-gnu/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10" title="#10: Bugs: allyourbase.jam file is bad. (closed: Out of Date)">#10</a> 0x00007ffff482bb4c in <span class="underline">libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11" title="#11: Bugs: why not using mt19937? (closed: Fixed)">#11</a> 0x00000000004accf9 in _start () </span></p> <p> Also getting same memory leak logs as mentioned in bug. </p> <p> This is stopping our upgrade to latest 1.65 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 27 Sep 2017 12:29:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:4</guid> <description> <p> Backing out changes to singleton.hpp solves the issue. </p> <p> Need to know the implication of it ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>James E. King, III</dc:creator> <pubDate>Fri, 20 Oct 2017 20:52:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:5</guid> <description> <p> See <a class="ext-link" href="https://github.com/boostorg/serialization/pull/69"><span class="icon">​</span>https://github.com/boostorg/serialization/pull/69</a> for more details. Someone submitted a fix. </p> </description> <category>Ticket</category> </item> <item> <author>gast128@…</author> <pubDate>Mon, 29 Jan 2018 15:21:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:6</guid> <description> <p> This is breaking for us and still present in 1.66. We look at the Visual Studio output and it should be clean. Once memory leak reports appear there one won't be able to distinguish a benign one from a serious one. </p> <p> The destructor of the singleton (which would free the memory) is never called. Trying to work around and making a singleton by hand leads to a stack overflow (0xC00000FD): </p> <div class="wiki-code"><div class="code"><pre><span class="k">struct</span> <span class="n">Bla</span> <span class="p">{</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span> <span class="nc">Archive</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">serialize</span><span class="p">(</span><span class="n">Archive</span><span class="o">&amp;</span> <span class="n">ar</span><span class="p">,</span> <span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">version</span><span class="p">)</span> <span class="p">{</span> <span class="n">ar</span> <span class="o">&amp;</span> <span class="n">boost</span><span class="o">::</span><span class="n">serialization</span><span class="o">::</span><span class="n">make_nvp</span><span class="p">(</span><span class="s">&quot;m_n&quot;</span><span class="p">,</span> <span class="n">m_n</span><span class="p">);</span> <span class="p">}</span> <span class="kt">int</span> <span class="n">m_n</span><span class="p">;</span> <span class="p">};</span> <span class="k">const</span> <span class="n">boost</span><span class="o">::</span><span class="n">serialization</span><span class="o">::</span><span class="n">singleton</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">serialization</span><span class="o">::</span><span class="n">extended_type_info_typeid</span><span class="o">&lt;</span><span class="n">Bla</span><span class="o">&gt;&gt;</span> <span class="n">g_singleton</span><span class="p">;</span> </pre></div></div> </description> <category>Ticket</category> </item> <item> <author>gast128@…</author> <pubDate>Tue, 30 Jan 2018 11:51:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:7</guid> <description> <p> Copy of my <a class="missing wiki">GitHub</a> comment: </p> <p> The Boost.Serialization singleton is never cleaned up leading to memory leaks. Even more severely it seems to crash our application now if a DLL's is dynamically unloaded and loaded. It seems related to registration of types in a singleton. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 20 Mar 2018 09:34:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:8</guid> <description> <p> So, what is the current state of this? To put it mildly, this is quite annoying. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>David</dc:creator> <pubDate>Wed, 28 Mar 2018 07:44:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:9</guid> <description> <p> Hi guys, just tripped over this as well. </p> <p> I'm using VS2017, and using the serialization library now produces memory leaks when the program is terminated. </p> <p> I see that in the Boost beta 1.67 release notes there's nothing there related to this problem. Is someone looking at the issue? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Tobias Loew</dc:creator> <pubDate>Wed, 11 Apr 2018 16:53:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:10</guid> <description> <p> Hi, </p> <p> I've also noted the memory-leaks. They origin from <a class="ext-link" href="https://github.com/boostorg/serialization/pull/79"><span class="icon">​</span>https://github.com/boostorg/serialization/pull/79</a> I (tobias-loew) already tried to convince those guys that they're off tracks but they seem resistant to advice. Please help here <a class="ext-link" href="https://github.com/boostorg/serialization/issues/102"><span class="icon">​</span>https://github.com/boostorg/serialization/issues/102</a> to convince Robert Ramey to revert those changes. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 22 Jun 2018 01:17:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13186#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13186#comment:11</guid> <description> <p> Same issue. Our team is moving to VS2017, and Boost 1.67 was supposed to be the first release with official support for that compiler/build environment, so we switched over to it. And now we're getting spammed with memory leak notifications in debugger console, upon program exit. Very disappointing to see this is still a problem 10 months after the bug was first reported! </p> </description> <category>Ticket</category> </item> </channel> </rss>