Boost C++ Libraries: Ticket #3432: Boost:Test pointer error with g++ 64-bit on Mac OS X 10.6 Snow Leopard https://svn.boost.org/trac10/ticket/3432 <p> When I compile a program which uses Boost:Test on Mac OS X 10.6 "Snow Leopard" for 64-bit architecture, I get an error when the program is run. To demonstrate this error, I creating a sample program (see attached file), which contains 10 test suites, each containing 10 test cases. The error only appears after a certain number of test suites/cases have been added to the program, because I could not reproduce the error with 10 test suites with 1 test case each. The compile commands and out put are: </p> <pre class="wiki">$ g++ -g -c -fmessage-length=0 -o"src/UnitTest.o" "../src/UnitTest.cpp" $ g++ -o "UnitTest" ./src/UnitTest.o $ ./UnitTest Running 100 test cases... *** No errors detected UnitTest(73438) malloc: *** error for object 0x3000100600630: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap </pre><p> I then tried compiling this with g++ 4.0.1 (apple), g++ 4.2.1 (apple), g++ 4.4.1, and icpc 11.1 with and without -m32 option; all on Mac OS X 10.6. In addition, I also compiled my test program with g++ 4.3.3 on Ubuntu Linux 9.04 (x86_64 version) with and without -m32 option. Here are the results of those tests. </p> <p> g++ Mac OS X 10.6: v 4.0.1 32bit: Pass v 4.0.1 64bit: Fail v 4.2.1 32bit: Pass v 4.2.1 64bit: Fail v 4.4.1 32bit: Pass v 4.4.1 64bit: Fail </p> <p> icpc Mac OS X 10.6: v 11.1 32bit: Pass v 11.1 64bit: Pass </p> <p> g++ Linux x86_64: v 4.3.3 64bit: Pass </p> <p> It appears that the error only occurs with g++ 64bit code on Mac OS X. </p> <p> While debugging the program I found that the error occurs in boost/test/impl/framework.ipp in void boost::unit_test::framework_imp::clean(), when delete is called. However, I do not think the error is in this function. Since the problem is not present when it is compiled as a 32-bit program, it is likely caused by a 64-bit value being written to a 32-bit address or something like that. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3432 Trac 1.4.3 Justus Calvin <justus.c79@…> Thu, 10 Sep 2009 20:07:36 GMT attachment set https://svn.boost.org/trac10/ticket/3432 https://svn.boost.org/trac10/ticket/3432 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">UnitTest.cpp</span> </li> </ul> Ticket janm@… Thu, 17 Sep 2009 14:13:25 GMT <link>https://svn.boost.org/trac10/ticket/3432#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3432#comment:1</guid> <description> <p> I see this problem on Mac OSX 10.6.1 as in the original report, and also on FreeBSD 7.2-STABLE, 64 bit version. I do not see the problem on 32 bit Windows XP with Visual C++ 2005 Express. </p> </description> <category>Ticket</category> </item> <item> <author>Justus Calvin <justus.c79@…></author> <pubDate>Thu, 17 Sep 2009 19:17:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3432#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3432#comment:2</guid> <description> <p> If I remember correctly, Mac OS X is a derivative of FreeBSD. I do not know how much they have in common today, but it is possible that it is a bug which still exists in the two OS's. </p> </description> <category>Ticket</category> </item> <item> <author>janm@…</author> <pubDate>Fri, 18 Sep 2009 01:34:51 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/3432 https://svn.boost.org/trac10/ticket/3432 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">double_free.cpp</span> </li> </ul> <p> Test case with a single unit test. </p> Ticket janm@… Fri, 18 Sep 2009 01:41:07 GMT <link>https://svn.boost.org/trac10/ticket/3432#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3432#comment:3</guid> <description> <p> For me it fails in the attached example with a single case on FreeBSD. On OS X I need more test cases to show the problem. </p> <p> The point of failure is the same on both platforms. </p> <p> On OS X and FreeBSD background: Possible, but also possibly not. I'd prefer not to jump to conclusions. </p> </description> <category>Ticket</category> </item> <item> <author>janm@…</author> <pubDate>Fri, 18 Sep 2009 02:40:31 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/3432 https://svn.boost.org/trac10/ticket/3432 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">framework.ipp.patch</span> </li> </ul> <p> Patch to resolve the problem. </p> Ticket janm@… Fri, 18 Sep 2009 02:47:02 GMT <link>https://svn.boost.org/trac10/ticket/3432#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3432#comment:4</guid> <description> <p> Please see the attached patch. This resolves the problem for me on OS X and FreeBSD. </p> <p> On OS X the single test case example can be made to fail by setting the "<a class="missing wiki">MallocScribble</a>" environment variable. </p> <p> The problem is that the delete in framework_impl::clear() happens through a reference to the actual pointer in the m_test_units container, and the destructor of the object removes itself from the container. Once the object is removed from the container (in the the destructor) the reference is no longer valid, and the underlying call to free() uses the now-invalid reference. </p> <p> Solution: Keep a copy of the pointer to be deleted on the stack. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Gennadiy Rozental</dc:creator> <pubDate>Tue, 29 Sep 2009 01:33:39 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3432#comment:5 https://svn.boost.org/trac10/ticket/3432#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/56467" title="apparently compiler might want to examine tu.second twice: before and ...">[56467]</a>) apparently compiler might want to examine tu.second twice: before and after calling destructor Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2889" title="#2889: Bugs: Unit Test framework does things that OS X's malloc dislikes (closed: fixed)">#2889</a> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3432" title="#3432: Bugs: Boost:Test pointer error with g++ 64-bit on Mac OS X 10.6 Snow Leopard (closed: fixed)">#3432</a> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2647" title="#2647: Patches: valgrind error with Boost.Test (closed: fixed)">#2647</a> </p> Ticket