"Trying to free invalid pointer" error detected in destructor
<p>I am in the beginning stages of writing a fairly large code. I have defined one class as such:</p>

<pre><code>class GPUMD {
    private:
        double xhi, xlo, yhi, ylo, zhi, zlo;
        int numAtoms;
        Atom *atoms;
    public:
        GPUMD();
        ~GPUMD();
};
</code></pre>

<p>The destructor is defined as below:</p>

<pre><code>GPUMD::~GPUMD() {
    if(atoms != NULL)
        delete [] atoms;
}
</code></pre>

<p>Right now, the code does this:</p>

<pre><code>int main(int argc, char *argv[]) {
    GPUMD gpumd;
    exit(0);
}
</code></pre>

<p>I get a glibc detected error: trying to free invalid pointer. Using valgrind, I see that this error traces to my destructor for GPUMD. For some reason, the atoms != NULL test is returning true even though I have not assigned anything to that pointer. Why is that?</p>

<p>EDIT: The constructor is defined as:</p>

<pre><code>GPUMD::GPUMD() {}
</code></pre>
