]> git.lyx.org Git - features.git/commitdiff
Fix memory errors found by Alfredo with valgrind
authorGeorg Baum <baum@lyx.org>
Wed, 12 Nov 2014 19:31:32 +0000 (20:31 +0100)
committerGeorg Baum <baum@lyx.org>
Wed, 12 Nov 2014 19:31:32 +0000 (20:31 +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
status.21x

index 3b6ee97a03d623d283d08ed9e9be10b6552222f0..a7f92d6d24bc3dce12ed7dbc33c50ef66d9b001d 100644 (file)
@@ -496,6 +496,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
index 2e94b3ca4ee245be477289ed7f754da7b8fec965..e368448741355d639b799cfc20b6932a5812d225 100644 (file)
@@ -113,6 +113,8 @@ What's new
 
 - Fix wrong test in LyX server.
 
+- Fix possible memory corruption on copying to the clipboard
+
 
 * DOCUMENTATION AND LOCALIZATION