Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That type of error is usually associated with multiple deletions (or frees) of the same pointer, or with some more obscure situations (acquiring from one heap and releasing to a different heap, but that is probably not the case here). </p> <p>The first thing I would do is look a the destructors and check that you are not shallow copying and doubly deleting. For example with the following code:</p> <pre><code>// buggy!!! struct test { int * data; test() : data( new int[5] ) {} ~test() { delete [] data; } test( test const &amp; rhs ) : data( rhs.data ) {} test&amp; operator=( test const &amp; rhs ) { data = rhs.data; } }; int main() { test t1; // 5 ints allocated int t1.data test t2( t1 ); // no memory allocated, t2.data == t1.data } // t2 out of scope: t2.~test() =&gt; delete t2.data // t1 out of scope: t1.~test() =&gt; delete t1.data but both are the same: double delete </code></pre> <p>If this is the case, you can decide whether you want to have shallow copies or make deep copies. In the second case the copy constructor (and assignment operator) should allocate their own memory, while in the second case you must ensure that the memory is not released twice.</p> <p>As always with pointers, it is better to delegate resource management to external (pre-built) classes. In the case of unique ownership (and deep copies) you should probably use <code>std::auto_ptr</code> (or <code>std::unique_ptr</code> in C++0x -- or the boost variants). In the second case, using <code>boost::shared_ptr</code> (or <code>std::shared_ptr</code> in C++0x) will ensure that the data is shared and only deleted once.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload