title: Crash from a push_back() in a std vector
body: <p>This program works as expected:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;    
  using namespace std;
  
  struct Thumbnail
  {
      string  tag;
      string  fileName;
  };
  
  int main()
  {
      {
          Thumbnail newThumbnail;
          newThumbnail.tag = "Test_tag";
          newThumbnail.fileName = "Test_filename.jpg";
  
          std::vector&lt;Thumbnail&gt; thumbnails;
  
          for(int i = 0; i &lt; 10; ++i) {
              thumbnails.push_back(newThumbnail);
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>If I copy and paste the main block of code in another project (still single threaded), inside any function, I get this exception from the line commented <code>// &lt;-- crash at the 2nd loop</code>:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::bad_alloc'
    what():  std::bad_alloc
  </code></pre>
  
  <p>If I clear the vector before any push_back, everything is all right (but of course this is not the desired behaviour); this makes me think that it is like if the vector could not store more than one such object.</p>
  
  <p>This is the function where the code is crashing:</p>
  
  <pre><code>int ImageThumbnails::Load(const std::string &amp;_path)
  {
      QDir thumbDir(_path.c_str());
  
      if(!thumbDir.exists())
          return errMissingThumbPath;
  
      // Set a filter
      thumbDir.setFilter(QDir::Files);
      thumbDir.setNameFilters(QStringList() &lt;&lt; "*.jpg" &lt;&lt; "*.jpeg" &lt;&lt; "*.png");
      thumbDir.setSorting(QDir::Name);
  
      // Delete previous thumbnails
      thumbnails.clear();
  
      Thumbnail newThumbnail;
  
      ///+TEST+++
      {
          Thumbnail newThumbnail;
          newThumbnail.tag = "Test_tag";
          newThumbnail.fileName = "Test_filename.jpg";
  
          std::vector&lt;Thumbnail&gt; thumbnails;
  
          for(int i = 0; i &lt; 10; ++i)
          {
              TRACE &lt;&lt; i &lt;&lt; ": " &lt;&lt; sizeof(newThumbnail) &lt;&lt; "  /  " &lt;&lt; newThumbnail.tag.size() &lt;&lt; " / " &lt;&lt; newThumbnail.fileName.size() &lt;&lt; std::endl;
              //thumbnails.clear();                   // Ok with this decommented
              thumbnails.push_back(newThumbnail);     // &lt;-- crash at the 2nd loop
          }
  
          exit(0);
      }
      ///+TEST+END+++
  ...
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>&gt; TRACE: ImageThumbnails.cpp:134:Load  
  0: 8  /  8 / 17
  &gt; TRACE: ImageThumbnails.cpp:134:Load  
  1: 8  /  8 / 17
  terminate called after throwing an instance of 'std::bad_alloc'
    what():  std::bad_alloc
  </code></pre>
  
  <p>Why do I get this different behaviour for the same piece of code in two different projects?  </p>
  
  <p>Platform: Windows 7, MinGW 4.4, GCC</p>