title: C++ delete[] on new char;
body: <p>Consider the following code:</p>
  
  <pre><code>int main()
  {
      char* str = new char; 
      str[0] = 'a'; 
      delete[] str; //Notice the []
  }
  </code></pre>
  
  <p>It compiles, runs and nothing crashes (VC15 and g++)
  It does however have 1 memory leak which I can clearly see with valgrind.</p>
  
  <p>If I run the following code however:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Foo{
  public:
      Foo(){
          std::cout &lt;&lt; "Foo::Foo" &lt;&lt; std::endl;
      }
      ~Foo(){
          std::cout &lt;&lt; "Foo::~Foo" &lt;&lt; std::endl;
      }
  };
  
  int main()
  {   
        Foo* foo = new Foo;
        delete[] foo;
        return 0;
  }
  </code></pre>
  
  <p>I get an infinite loop of destructor calls when running on Windows, and an invalid pointer error in Linux (after ~20 d'tors calls).</p>
  
  <p>What I can't figure out is why is there a difference between the two? why don't I get an infinite loop with <code>new char</code> or crash? </p>