]> git.lyx.org Git - lyx.git/commitdiff
Fix crash when closing master with children and grandchildren
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 28 Sep 2017 07:06:33 +0000 (09:06 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 28 Sep 2017 07:09:36 +0000 (09:09 +0200)
In some cases, it is possible that the BufferPositionMap has
dangling pointers. We thus check whether the Buffer is loaded
before accessing it.

Fixes: #10766
(cherry picked from commit 4f50cbcfe405a840459be8682fd4c7521b235798)

src/Buffer.cpp

index 11e46ba0219230850edd3307b350824ecd071409..c4ce8ea053d45633e4ace7f8f3c4463e26047b14 100644 (file)
@@ -3720,8 +3720,12 @@ void Buffer::listMacroNames(MacroNameSet & macros) const
        // loop over children
        Impl::BufferPositionMap::iterator it = d->children_positions.begin();
        Impl::BufferPositionMap::iterator end = d->children_positions.end();
-       for (; it != end; ++it)
-               it->first->listMacroNames(macros);
+       for (; it != end; ++it) {
+               Buffer * child = const_cast<Buffer *>(it->first);
+               // The buffer might have been closed (see #10766).
+               if (theBufferList().isLoaded(child))
+                       child->listMacroNames(macros);
+       }
 
        // call parent
        Buffer const * const pbuf = d->parent();