"free(): invalid next size" when using std::map as a class member
Included here is a very simple class declaration. When this declaration
is placed in its own header file [test.hpp] and the class member
function definitions are placed in their own file [test.cpp], then the
simple usage case that follows results in a SIGABRT when built with GCC
v4.12 on SUSE Linux Enterprise Server v10.0 SP1.
header file "test.hpp":
#include <map>
class CTest01
{
public:
CTest01();
CTest01(const CTest01& X);
~CTest01();
CTest01& operator=(const CTest01& X);
protected:
private:
std::map<int, int> m_Map;
};
code module "test.cpp":
CTest01::CTest01()
:
m_Map()
{
return;
}
CTest01::CTest01(const CTest01&)
:
m_Map()
{
return;
}
CTest01::~CTest01()
{
return;
}
CTest01& CTest01::operator=(const CTest01&)
{
return (*this);
}
test case that uses CTest01:
#include "test.hpp"
int main(int argc, char* argv[])
{
CTest01 *pTest = NULL;
pTest = new CTest01();
if (NULL != pTest)
{
delete pTest;
}
return 0;
}
Building this as a console application on Windows Vista using Visual
C/C++ v9.0 [Visual Studio 2008] results in a binary that executes w/o
any faults.
Building this on SUSE Linux Enterprise Server v10.0 SP1 using GCC v4.12,
I get a clean compilation but a SIGABRT at run time.
"*** glibc detected *** ./x86_64/test: free(): invalid next size (fast):
0x0000000000588240 ***
followed by a back trace that I'll omit for now.
The problem occurs in the same way for both 32-bit and 64-bit builds,
running on i386 or x86_64 builds of SLES 10.
I'm not entirely certain if I'm dealing with a problem with GCC, a
problem with the glibc implementation on SLES 10 or if I'm missing some
subtle detail related to using std::map as a data member in another
class. So, I'm starting here and if it's necessary to take this to a
more appropriate newsgroup, I'll repost elsewhere as-needed.
Interestingly enough, if I combine the declaration & definition of
CTest01 and it's members directly into the file scope of the code that
makes use of CTest01, then the problem goes away. It's only when the
definition is in an external file that this problem occurs.
Using an std::list class object as a class data member in CTest01 does
not result in this problem occurring. It's only when I use a std::map
class object as a data member in CTest01 that this problem occurs.
Also, it makes no difference what values I use for the template
instantiation of std::map, as the problem happens with <int, int>,
<inst, std::string> and even <std::string, int>, etc....
Any ideas or thoughts as to what might be causing this?