commit 180ecbd79a9c99b8b8eeb00ce4906aa2a319c3f9
Author: Enrico Forestieri <for...@lyx.org>
Date:   Tue Jun 30 21:11:54 2015 +0200

    Avoid using a dangling pointer
    
    This can happen when a macro is copied and then the document where
    it is defined is closed. In this case, the macro survives in the
    cut stack but the the buffer pointer is dangling.
    
    This commit is an amendment to 2a9f0733 so no status line is needed.

diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index ed28927..491b75d 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -22,6 +22,7 @@
 #include "MathSupport.h"
 
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferView.h"
 #include "CoordCache.h"
 #include "Cursor.h"
@@ -180,7 +181,10 @@ void MathMacro::assign(MathMacro const & that)
                // We need to update macro_ by ourselves because in this case
                // MathData::metrics() is not called when selecting a math inset
                DocIterator const & pos = macroBackup_.pos();
-               macro_ = pos.buffer() ? pos.buffer()->getMacro(name(), pos) : 0;
+               Buffer const * buf = pos.buffer();
+               if (buf && !theBufferList().isLoaded(buf))
+                       buf = 0;
+               macro_ = buf ? buf->getMacro(name(), pos) : 0;
                if (!macro_)
                        macro_ = &macroBackup_;
        }

Reply via email to