title: List iterator not dereferencable?
body: <p>I get the error "list iterator not dereferencable" when using the following code:</p>
  
  <pre><code>bool done = false;
  while (!_list_of_messages.empty() &amp;&amp; !done) {
      // request the next message to create a frame
      // DEBUG ERROR WHEN NEXT LINE IS EXECUTED:
      Counted_message_reader reader = *(_list_of_messages.begin());
      if (reader.has_more_data()) {
          _list_of_frames.push_back(new Dlp_data_frame(reader, _send_compressed_frames));
          done = true;
      } else {
          _list_of_messages.pop_front();
      }
  }
  </code></pre>
  
  <p>(The line beginning with "Counted_message_reader..." is the one giving the problem)</p>
  
  <p>Note that the error doesn't always occur but seemingly at random times (usually when there's lots of buffered data).</p>
  
  <p><code>_list_of_messages</code> is declared as follows:</p>
  
  <pre><code>std::list&lt;Counted_message_reader&gt; _list_of_messages;
  </code></pre>
  
  <p>In the surrounding code we could do <code>pop_front</code>, <code>push_front</code> and <code>size</code>, <code>empty</code> or <code>end</code> checks on <code>_list_of_messages</code> but no <code>erase</code> calls. </p>
  
  <p>I've studied the STL documentation and can't see any glaring problems. Is there something wrong with the above code or do I have a memory leak somewhere?</p>
  
  <p>Thanks! Appreciated!</p>