]> git.lyx.org Git - lyx.git/blobdiff - src/BufferList.cpp
Amend 7e121117bb3203
[lyx.git] / src / BufferList.cpp
index b068f66e5e1ba4e66e92fa97faa7d47ad63199a5..a61b0bfd80fdd8d80229601eb96537b7b8557fa7 100644 (file)
@@ -96,10 +96,15 @@ void BufferList::release(Buffer * buf)
        BufferStorage::iterator const it =
                find(bstore.begin(), bstore.end(), buf);
        if (it != bstore.end()) {
+               Buffer const * parent = buf->parent();
                Buffer * tmp = (*it);
                bstore.erase(it);
                LASSERT(tmp, return);
                delete tmp;
+               if (parent)
+                       // If this was a child, update the parent's buffer
+                       // to avoid crashes due to dangling pointers (bug 9979)
+                       parent->updateBuffer();
        }
 }
 
@@ -196,7 +201,7 @@ Buffer * BufferList::next(Buffer const * buf) const
 
        if (bstore.empty())
                return 0;
-       BufferStorage::const_iterator it = 
+       BufferStorage::const_iterator it =
                        find(bstore.begin(), bstore.end(), buf);
        LASSERT(it != bstore.end(), return 0);
        ++it;
@@ -212,7 +217,7 @@ Buffer * BufferList::previous(Buffer const * buf) const
 
        if (bstore.empty())
                return 0;
-       BufferStorage::const_iterator it = 
+       BufferStorage::const_iterator it =
                        find(bstore.begin(), bstore.end(), buf);
        LASSERT(it != bstore.end(), return 0);
 
@@ -279,7 +284,7 @@ bool BufferList::isOthersChild(Buffer * parent, Buffer * child)
        LASSERT(parent, return false);
        LASSERT(child, return false);
        LASSERT(parent->isChild(child), return false);
-       
+
        // Does child document have a different parent?
        Buffer const * parent_ = child->parent();
        if (parent_ && parent_ != parent)