Boost logo

Boost Users :

Subject: [Boost-users] [test] Linking against boost_unit_test_framework causes double-deletion in std::ostringstream
From: Alastair Rankine (arsptr_at_[hidden])
Date: 2009-11-10 05:50:20


Just curious if anyone else has seen this or anything like it? Platform
is Mac OS X 10.6.1, gcc 4.2.1, boost 1.40.0 installed from MacPorts,
compiling 64-bit (default).

Here's my test code:

#include <sstream>

int main()
{
    std::ostringstream str;
    str << "Help Me!";

    return 0;
}

Here's what I'm doing:

% g++ -o streamtest_bad -ggdb -L/opt/local/lib
-lboost_unit_test_framework-mt-d streamtest.cpp
% ./streamtest_bad
streamtest_bad(63554) malloc: *** error for object 0x7fff7008a500:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
zsh: abort ./streamtest_bad
%

Works fine against other boost libraries, eg system:

% g++ -o streamtest_good -ggdb -L/opt/local/lib -lboost_system-mt-d
streamtest.cpp
% ./streamtest_good
%

Note that this seems to be a separate problem to that reported in
ticket 3432 (https://svn.boost.org/trac/boost/ticket/3432). At least, I
have verified that the framework::clear() function isn't being called
in the above code, which does tend to point the finger at a different
part of the library.

The backtrace is not particularly enlightening, but posted here for the
sake of completeness:

(gdb) bt
#0 0x00007fff87f92ff6 in __kill ()
#1 0x00007fff88034072 in abort ()
#2 0x00007fff87f4b095 in free ()
#3 0x0000000100005533 in __gnu_cxx::new_allocator<char>::deallocate
(this=0x7fff5fbff5df, __p=0x7fff7008a500 "") at new_allocator.h:97
#4 0x0000000100005578 in std::string::_Rep::_M_destroy
(this=0x7fff7008a500, __a=@0x7fff5fbff63f) at basic_string.tcc:431
#5 0x0000000100005939 in std::string::_Rep::_M_dispose
(this=0x7fff7008a500, __a=@0x7fff5fbff63f) at basic_string.h:238
#6 0x000000010000596a in std::basic_string<char,
std::char_traits<char>, std::allocator<char> >::~basic_string
(this=0x7fff5fbff670) at basic_string.h:493
#7 0x000000010002ad55 in std::basic_stringbuf<char,
std::char_traits<char>, std::allocator<char> >::overflow
(this=0x7fff5fbff7f8, __c=72) at sstream.tcc:125
#8 0x0000000100029db0 in std::basic_streambuf<char,
std::char_traits<char> >::xsputn (this=0x7fff5fbff7f8, __s=0x100000e7e
"Help Me!", __n=8) at streambuf.tcc:102
#9 0x00007fff806e0ae4 in std::__ostream_write<char,
std::char_traits<char> > ()
#10 0x00007fff806deb98 in std::__ostream_insert<char,
std::char_traits<char> > ()
#11 0x00007fff806dec58 in std::operator<< <std::char_traits<char> > ()
#12 0x0000000100000d6b in main () at streamtest.cpp:6


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net