3

I'm getting a weird error, when initializing my deque or vector. I'm using QtCreator and a CMake-Project.

If I use a deque, it aborts on initialization:

std::deque<int> myValues; // <-- abort here

for (int i=0;i<10;++i)
{
    myValues.push_back(i);
}

when I use deque, it aborts on push_back:

std::vector<int> myValues; 

for (int i=0;i<10;++i)
{
    myValues.push_back(i); // <-- abort here
}

I can't find out why this is happening now (it worked that way all the time). Both aborts happen inside _gnu_cxx::new_allocator< int >::allocate.

Any hints?

Thanks for the effort in advance!

Hartmut

hardmooth
  • 1,202
  • 2
  • 19
  • 36
  • Something appears to be fishy with allocating memory. Does a `malloc`/`free` work, or do they raise SIGABRT as well? My guess is that the internal bookkeeping in glibc done by those functions is messed up. Try running Valgrind on your application, maybe it can shed some light. – Frerich Raabe Jul 03 '12 at 10:27
  • You must be invoking some undefined behaviour somewhere else in the program. Check whether you are doing stuff such as accessing out of bounds memory locations. – juanchopanza Jul 03 '12 at 10:27

1 Answers1

2

It looks like a heap corruption in some other place in your program. That is, you write out-of-bounds or delete an invalid pointer somewhere. Once the heap internal structure is corrupted, substantial allocations may crash your program.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
  • thanks. After uncommenting some other functions (which didn't cause any errors) of the namespace, it went through. – hardmooth Jul 03 '12 at 11:23
  • 1
    @hartmooth Well those functions were causing errors (namely heap corruption), they just weren't causing obvious and easy to fix errors. – sashoalm Jul 03 '12 at 11:34