freeing in the destructor is causing a memory leak
<p>I have to write a stack class template using arrays in C++ for my assignment. 
<a href="http://pastebin.com/m1948c5f5" rel="nofollow">Here</a> is my code:</p>

<pre><code>#include &lt;iostream&gt;

template &lt;typename Type&gt;
class Stack {
private:
  int top;
  Type items[];
public:
  Stack()  { top = -1; };
  ~Stack() { delete[] items; };
  void push(Type);
  bool isEmpty() const;
  Type pop();
  Type peek() const;
};

int main (int argc, char *argv[]) {
  Stack&lt;double&gt; st;
  return 0;
}

template&lt;typename Type&gt;
void Stack&lt;Type&gt;::push(Type item) {
  top++;
  if(top == sizeof(items) / sizeof(Type)) {
    Type buff[] = new Type[top];
    std::copy(items,items+top,buff);
    delete[] items;
    items = new Type[2*top];
    std::copy(buff,buff+top,items);
    delete[] buff;
  }
  items[top] = item;
}

template&lt;typename Type&gt;
bool Stack&lt;Type&gt;::isEmpty() const {
  return top == -1 ? true : false;
}

template&lt;typename Type&gt;
Type Stack&lt;Type&gt;::pop() {
  //TODO
  return items[top--];
}

template&lt;typename Type&gt;
Type Stack&lt;Type&gt;::peek() const{
  //TODO
  return items[top-1];
}
</code></pre>

<p>It compiled fine using "<code>g++ -Wall</code>", however when I run the program, I got this error:</p>

<blockquote>
  <p><strong>* glibc detected *</strong> <code>./lab3: munmap_chunk(): invalid pointer: 0x00007fff41a3cdf8</code></p>
</blockquote>

<p>After trying out a bit with gdb, I found out the error arose from the line:</p>

<pre><code>'free[] items' in the destructor.
</code></pre>

<p>I don't understand why freeing an array results in a memory leak ? Any clues ?</p>
