title: Debug Assertion Failed: _CrtIsValidHeapPointer(pUserData)
body: <p><em>Sometimes</em> I get this "Debug Assertion Failed" error running my Qt project in debug mode (<a href="https://docs.google.com/open?id=0B2Yd07bQCHDGd2xmQWo3dEx5c1k" rel="noreferrer">image</a>).
  I don't know where I wrong because the compiler says nothing and I don't know what to do to find my error.</p>
  
  <p>I program under Windows Vista, using Qt Creator 2.4.1, Qt 4.8.1.</p>
  
  <p>My program has to read some informations from a laser device and save them into a file with a code similar to this:</p>
  
  <pre><code>void runFunction()
  {
      configure_Scanning(...);
  
      while(...)
      {
          // do something
          scanFunction();
          // do something
      }
  }
  </code></pre>
  
  <p>and this is my "incriminated" function (where I think the problem is)</p>
  
  <pre><code>void scanFunction()
  {
      file.open();
  
      data = getDataFromDevice();
  
      if(flag)
      {
          if(QString::compare(lineB,"")!=0)
          {
              QTextStream out(&amp;file);
              out &lt;&lt; lineB &lt;&lt; endl;
              lineB = "";
          }
          lineA.append(data+"\t");
      }
      else
      {
          if(QString::compare(lineA,"")!=0)
          {
              QTextStream out(&amp;file);
              out &lt;&lt; lineA &lt;&lt; endl;
              lineA = "";
          }
          lineB.prepend(data+"\t");
      }
  
      file.close();
  }
  </code></pre>
  
  <p>Where <em>lineA</em> and <em>lineB</em> are initially two void QString: the idea is that I make a bidirectional scanning to save informations in a 2D matrix (from -X to +X and viceversa, while Y goes to a specified target). <em>lineA</em> memorizes the (-)to(+) reading; <em>lineB</em> memorizes the (+)to(-) reading. When the scanning direction changes, I write <em>lineA</em> (or <em>lineB</em>) to the file and I proceed with the scanning.</p>
  
  <p>Do you understand what I said?
  Could you suggest me a solution?</p>
  
  <p>Thanks and sorry for my English :P</p>