title: malloc: *** error for object: pointer being freed was not allocated
body: <p>I keep getting this error when I run my code. I'm not sure why I keep getting this error because I call <code>delete</code> on two objects which I have allocated using the <code>new</code> operator.</p>
  
  <p>I have tried running it in Xcode and I get a <code>thread 1: signal SIGABRT error</code>.</p>
  
  <p><strong>PokerV2.cpp</strong></p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main() {    
      bool game_flag = true;
  
      Poker_Game game1;
  
      game1.initialise_game();
  
      game1.game_run();
  
      while (game_flag) { 
          char input = 'a';
          game_flag = false;
          game1.game_run(game1.get_current_players());
          std::cout &lt;&lt; "Press 'y' to continue";
          std::cin &gt;&gt; input;
          if (input == 'y') {
              game_flag = true;
          }
      }
  }
  </code></pre>
  
  <p><strong>poker_game_class.hpp</strong></p>
  
  <pre class="lang-cpp prettyprint-override"><code>void Poker_Game::game_run() {
      int lowest = 10;
      int num = 0;
      // Create the deck and table dynamically
      Deck *deck = new Deck();
      Table *table = new Table(_player_num);
  
      deck-&gt;deal_cards(table-&gt;get_all_players(), _player_num, *table);
  
      for (int i = 0; i &lt; 4; i++) {
          table-&gt;set_game_flag(i);
          table-&gt;set_highest_bet(0);
  
          for (int z = 0; z &lt; table-&gt;get_player_num(); z++) {
              table-&gt;players_turn(z);
          }
      }
  
      for (int i = 0; i &lt; table-&gt;get_player_num(); i++) {
          if (table-&gt;get_player(i).calculate_score(*table) &lt; lowest) {
              num = i;
          }
      }
  
      std::cout &lt;&lt; "The winner is player: " &lt;&lt; num &lt;&lt; "\n";
      std::cout &lt;&lt; "The winner has won: £" &lt;&lt; table-&gt;get_pot() &lt;&lt; "\n";
  
      //Add total pot to players cash
  
      float current_balance = table-&gt;get_player(num).get_balance();
      float balance_after_win = current_balance + table-&gt;get_pot();
  
      table-&gt;get_player(num).set_balance(balance_after_win);
  
      std::cout &lt;&lt; "Winners balance: £" &lt;&lt; table-&gt;get_player(num).get_balance();
  
      this-&gt;Current_players = table-&gt;get_all_players();
  
      delete deck;
      delete table;
  }
  </code></pre>
  
  <p>The error occurs in the <code>game_run</code> function just when the <code>deck</code> and <code>table</code> are deleted.</p>
  
  <p><a href="https://i.stack.imgur.com/TO9FO.png" rel="nofollow noreferrer">The output from the terminal</a> </p>
  
  <p>Below is the linked GitHub repository</p>
  
  <p><a href="https://github.com/mbh1620/PokerV2/tree/master/PokerV2" rel="nofollow noreferrer">https://github.com/mbh1620/PokerV2/tree/master/PokerV2</a></p>