title: Why does my destructor only crash my code after it's called by its parent destructor?
body: <p>I have a doubly threaded linked list made up of <code>winery</code> elements, <code>winery</code> being a class with its own data fields. The problem that I was having was with <code>winery</code>'s destructor:</p>
  <pre><code>winery::~winery()
  {
          delete[] name;
          delete[] location;
  }
  </code></pre>
  <p>I received a &quot;double free or corruption (out): 0x0000000000402940&quot; error in Linux, and I received this error in Windows Visual Studio:</p>
  <p><a href="https://i.imgur.com/eezTML2.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/eezTML2.png" alt="enter image description here" /></a></p>
  <p>So I put a breakpoint on my <code>winery</code>'s destructor and found that it was being called every time I referenced my winery object. Strangely, the only time an error was thrown was when <code>winery</code>'s destructor was called because my <code>list</code>'s destructor had been called, even if winery had already been called two or three times. I would like to know why my code didn't crash the second time <code>winery</code>'s destructor was called when it wasn't called by its parent destructor.</p>
  <br>
  <br>
  <p><strong>As a side note/question:</strong> I was able to solve this issue of memory leakage by removing <code>winery</code>'s destructor and putting its calls in it parent destructor like this:</p>
  <pre><code>list::~list()
  {
      for (node* next; headByName; headByName = next)
      {
          next = headByName-&gt;nextByName;
          delete[] headByName-&gt;item.getName();
          delete[] headByName-&gt;item.getLocation();
          delete headByName;
      }
  }
  </code></pre>
  <p><code>winery</code> is a type with name <code>'item'</code> and <code>getName()</code> and <code>getLocation()</code> are functions of winery which return those cstrings. This works but it's counter-intuitive, and it certainly <em>seems</em> inefficient. Is it bad code? Should I be using `winery's destructor and overriding when it's called somehow?</p>