title: free(): double free detected in tcache 2 (because of destructor )
body: <p>I have a program that has a dynamic array of Players within a Team, and a dynamic array of teams in a league. I know I could use vector, but I want to learn how to use dynamic arrays and how memory works.</p>
  <p>When I create two team objects, I get a free(): double free detected in tcache 2 error. I ran valgrind and I commented stuff out until I deduced it was because of my destructor, but I don't know how to fix it. I get many memory leaks without the destructor.</p>
  <p>Any help is appreciated. Here is my code in the file with the error:</p>
  <pre><code>#include &quot;Team.h&quot;
  #include &lt;sstream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  Team::Team() {
     location = &quot;&quot;;
     nickname = &quot;&quot;;
     num_players = 0;
  
     maxSize = 1;
     currentSize = 0;
     players = new Player[maxSize];
  }
  
  Team::Team(const std::string &amp;loc, const std::string &amp;name) {
     location = loc; 
     nickname = name; 
     num_players = 0;
  
     
     maxSize = 1;
     currentSize = 0;
     players = new Player[maxSize];
     
  }
  
  Team::~Team(){
     if(players){
     delete [] players;}
  }
  
  void Team::grow(){
     maxSize = currentSize * 2;
     Player* newList = new Player[maxSize];
  
     for (unsigned i = 0; i &lt; currentSize; i++){
        newList[i] = players[i];
     }
  
     delete [] players;
     players = newList;
  
  }
  
  void Team::addPlayer(const Player &amp;p) {
     if (currentSize == maxSize){
        grow();
     }
     players[currentSize++] = p;
  
  }
  
  void Team::showTeam() const {
     std::cout &lt;&lt; location &lt;&lt; &quot; &quot; &lt;&lt; nickname /*&quot;(&quot; &lt;&lt; currentSize &lt;&lt; &quot; &quot; &lt;&lt; &quot;players&quot; &lt;&lt; &quot;)&quot;*/ &lt;&lt; endl;   
  }
  
  void Team::showPlayers() const {
     std::cout &lt;&lt; &quot;   Players:&quot; &lt;&lt; std::endl;
     for (unsigned int i = 0; i &lt; num_players; i++) {
        player[i].show();
     }
  }
  
  std::ostream &amp;operator&lt;&lt;(std::ostream &amp;out, const Team &amp;tm) {
     tm.showTeam();
     return out;
  }
  </code></pre>