title: Dealing with an object corrupting the heap
body: <p>In my application I am creating an object pretty much like this : </p>
  
  <pre><code>connect() {
    mVHTGlove = new vhtGlove(params);
  }
  </code></pre>
  
  <p>and once I am about to close application I call this one :</p>
  
  <pre><code>disconnect() {
    if (mVHTGlove) 
      delete mVHTGlove;
  }
  </code></pre>
  
  <p>This call always triggers a breakpoint with the following message :</p>
  
  <blockquote>
    <p>Windows has triggered a breakpoint in
    DesignerDynD.exe.</p>
    
    <p>This may be due to a corruption of the
    heap, which indicates a bug in
    DesignerDynD.exe or any of the DLLs it
    has loaded.</p>
    
    <p>This may also be due to the user
    pressing F12 while DesignerDynD.exe
    has focus.</p>
    
    <p>The output window may have more
    diagnostic information.</p>
  </blockquote>
  
  <p>I cannot modify the vhtGlove class to fix the corruption of the stack as it is an external library provided only in the form of header files, lib files and dlls.</p>
  
  <p>Is there any way to use this class in a clean way ?</p>
  
  <hr>
  
  <p>**** EDIT ::: I tried to strip things down to a bare minimum, however I get the same results... here you have the ENTIRE code.</p>
  
  <pre><code>#include "vhandtk/vhtCyberGlove.h"
  #include "vhandtk/vhtIOConn.h"
  #include "vhandtk/vhtBaseException.h"
  
  using namespace std;
  
  int main(int argc, char* argv[])
  {
     vhtCyberGlove* testGlove = NULL;
  
     vhtIOConn gloveAddress("cyberglove", "localhost", "12345", "com1", "115200");
     try
     {
        testGlove = new vhtCyberGlove(&amp;gloveAddress,false);
  
        if (testGlove-&gt;connect())
           cout &lt;&lt; "Glove connected successfully" &lt;&lt; endl;
        else
        {
           throw vhtBaseException("testGlove()-&gt;connect() returned false.");
        }
  
        if (testGlove-&gt;disconnect())
        {
           cout &lt;&lt; "Glove disconnected successfully" &lt;&lt; endl;
        }
        else 
        {
           throw vhtBaseException("testGlove()-&gt;disconnect() returned false.");
        }
  
     }
     catch (vhtBaseException *e)
     {
        cout &lt;&lt; "Error with gloves: " &lt;&lt; e &lt;&lt; endl;
        system("pause");
        exit(0);
     }
  
     delete testGlove;
  
     return 0;
  }
  </code></pre>
  
  <p>Still crashes on deletion of the glove.</p>
  
  <hr>
  
  <p>EDIT #2 :: If I just allocate and delete an instance of vhtCyberGlove it also crashes.</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
     vhtCyberGlove* testGlove = NULL;
     vhtIOConn gloveAddress("cyberglove", "localhost", "12345", "com1", "115200");
     testGlove = new vhtCyberGlove(&amp;gloveAddress,false);
     delete testGlove; //&lt;&lt;crash!
     return 0;
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>thanks!</p>
  
  <p>JC</p>