Double free exception with Vector

J

jois.de.vivre

I am having some difficulty with the STL vector class throwing a double
free exception. The problem is that I don't use pointers anywhere in
my program. The double free currently occurs when I call push_back().
The stack trace shows that the double free stems from the following
lines in vector.tcc (from gcc):

....
....
_M_deallocate(this->_M_impl._M_start,
this->_M_impl._M_end_of_storage
- this->_M_impl._M_start);
....
....

This line is in the function:

template<typename _Tp, typename _Alloc>
vector<_Tp, _Alloc>&
vector<_Tp, _Alloc>::
operator=(const vector<_Tp, _Alloc>& __x);

This happens when I try and use push_back() on a private variable from
within the class. If I try it on a local variable everything operates
as expected. I tried to trace the problem down to see what exactly the
variable "_M_impl" is, but I couldn't find it. Also, the coding
convention used is a bit unintuitive and I couldn't figure out from the
code what exactly the purpose of this line was. I suppose it is
deallocating something from start to end, and my problem is that this
has been deallocated as some time in the past already. I would post my
code, but it's part of a larger application and not very simple. I
tried to contrive an example, but I couldn't reproduce the problem.
Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top