Enumerate an iterator not to reverse?

I get the error "list iterator not dereferencable" when using the following code:

bool done = false;
while (!_list_of_messages.empty() && !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();
    }
}

(the line starting with "Counted_message_reader ..." is the one that gives the problem)

Note that an error does not always occur, but apparently at a random time (usually when there is a lot of buffered data).

_list_of_messages declared as follows:

std::list<Counted_message_reader> _list_of_messages;

In the surrounding code, we could execute pop_front, push_frontand size, emptyor endcheck for _list_of_messages, but not call erase.

I have studied the STL documentation and do not see any obvious problems. Is there something wrong with the above code, or do I have a memory leak somewhere?

Thank! Appreciated!

+5
3

?

, begin(), . , ?

VS 2008 (, typedef Counted_message_reader int).

+3

, , , " " .

+3

, , , . , , . -? ( , ).

0

All Articles