diff --git a/core/textpage.cpp b/core/textpage.cpp index 7bd1ec2c8..9143ee5da 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -1093,13 +1093,18 @@ void TextPagePrivate::removeSpace() const QString str(' '); it = m_words.begin(), itEnd = m_words.end(); - for( ; it != itEnd ; it++) + while ( it != itEnd ) { if((*it)->text() == str) { // create new Entity, otherwise there might be possible memory leakage m_spaces.append( new TinyTextEntity( (*it)->text(),(*it)->area ) ); - m_words.erase(it); + delete *it; + it = m_words.erase(it); + } + else + { + ++it; } } }