]> git.lyx.org Git - features.git/commitdiff
Fix dangling inset pointers after buffer reload
authorGuillaume Munch <gm@lyx.org>
Sat, 31 Dec 2016 14:16:15 +0000 (15:16 +0100)
committerGuillaume Munch <gm@lyx.org>
Sat, 31 Dec 2016 14:16:15 +0000 (15:16 +0100)
https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg198191.html

The root of the issue is in Buffer::reload() called during "Save As".  After
loadLyXFile() there, all the insets have been deleted, and therefore the Inset
pointer GuiView::documentBufferView()->cursor().inset() is dangling. Immediately
after loadLyXFile(), reload() calls updateBuffer() which causes a segfault.

While debugging I got other segfaults caused by the same dangling Inset pointer
in Cursor, notably: 1) a trace identical to the second one from
<http://www.lyx.org/trac/ticket/10520>, and 2) a similar segfault in the
critical path after emergency saving (call to inMathed()).

Having to "refresh" by hand the inset pointer cache in CursorSlice is very
unsatisfactory, but there does not appears to be a consistent strategy for
managing these Inset pointers in CursorSlice.

src/frontends/qt4/GuiView.cpp

index 90b43eb629ad5d0b4598ea02e99bd28d1d86dbf6..2c481245680727876bc3d2c5f4171cec0a3608fb 100644 (file)
@@ -1652,6 +1652,10 @@ void GuiView::updateTocItem(string const & type, DocIterator const & dit)
 
 void GuiView::structureChanged()
 {
+       // This is called from the Buffer, which has no way to ensure that cursors
+       // in BufferView remain valid.
+       if (documentBufferView())
+               documentBufferView()->cursor().sanitize();
        // FIXME: This is slightly expensive, though less than the tocBackend update
        // (#9880). This also resets the view in the Toc Widget (#6675).
        d.toc_models_.reset(documentBufferView());