Double free exception with Vector

Discussion in 'C++' started by jois.de.vivre@gmail.com, Sep 14, 2005.

  1. Guest

    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?
    , Sep 14, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,430
    Victor Bazarov
    Feb 17, 2005
  2. Ingo Nolden
    Replies:
    15
    Views:
    1,507
    Jerry Coffin
    Apr 30, 2005
  3. Replies:
    2
    Views:
    274
    John Harrison
    Sep 15, 2005
  4. Replies:
    0
    Views:
    465
  5. Replies:
    8
    Views:
    1,877
    Csaba
    Feb 18, 2006
Loading...

Share This Page