]> git.lyx.org Git - features.git/commitdiff
Fix memory errors found by Alfredo with valgrind
authorGeorg Baum <baum@lyx.org>
Tue, 11 Nov 2014 06:42:54 +0000 (07:42 +0100)
committerGeorg Baum <baum@lyx.org>
Tue, 11 Nov 2014 19:57:25 +0000 (20:57 +0100)
BufferParams::setDocumentClass() deletes the old document class of the buffer
and creates a copy of the new one. Therefore, the stored layout pointers in
the paragraphs (actually only one paragraph exists) are dangling afterwards.
Resetting them before setting the document class helps here.
In the long term we need to get rid of BufferParams::setDocumentClass()
completely, this is very ugly.

src/CutAndPaste.cpp

index 7329c248918f95b0e60b446626c4e0a6dcd38a52..1a4d5f7d413f9f8e220c8995d89905ef62f683f4 100644 (file)
@@ -502,6 +502,17 @@ void putClipboard(ParagraphList const & paragraphs,
        LASSERT(buffer, return);
 
        // This needs doing every time.
+       // Since setDocumentClass() causes deletion of the old document class
+       // we need to reset all layout pointers in paragraphs (otherwise they
+       // would be dangling).
+       ParIterator const end = buffer->par_iterator_end();
+       for (ParIterator it = buffer->par_iterator_begin(); it != end; ++it) {
+               docstring const name = it->layout().name();
+               if (docclass->hasLayout(name))
+                       it->setLayout((*docclass)[name]);
+               else
+                       it->setPlainOrDefaultLayout(*docclass);
+       }
        buffer->params().setDocumentClass(docclass);
 
        // we will use pasteSelectionHelper to copy the paragraphs into the