]> git.lyx.org Git - features.git/commitdiff
Add assertion to check for memory leaks and remove the list when
authorRichard Heck <rgheck@comcast.net>
Sun, 20 Nov 2011 18:49:12 +0000 (18:49 +0000)
committerRichard Heck <rgheck@comcast.net>
Sun, 20 Nov 2011 18:49:12 +0000 (18:49 +0000)
we are done.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40228 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp

index 8abdcc8632106ce6fef8eb20fdf3a76b83556d22..cd3dcb85a7d33fe43f3eb6a04d827f7e6d653260 100644 (file)
@@ -143,7 +143,7 @@ void showPrintError(string const & name)
 
 
 // A storehouse for the cloned buffers.
-list<CloneList> cloned_buffers;
+list<CloneList *> cloned_buffers;
 
 
 class Buffer::Impl
@@ -413,6 +413,18 @@ Buffer::~Buffer()
                                if (d->clone_list_->erase(child))
                                        delete child;
                }
+               // if we're the master buffer, then we should get rid of the list
+               // of clones
+               if (!parent()) {
+                       // if this is not empty, we have leaked something. worse, one of the
+                       // children still has a reference to this list.
+                       LASSERT(d->clone_list_->empty(), /* */);
+                       list<CloneList *>::iterator it = 
+                               find(cloned_buffers.begin(), cloned_buffers.end(), d->clone_list_);
+                       LASSERT(it != cloned_buffers.end(), /* */);
+                       cloned_buffers.erase(it);
+                       delete d->clone_list_;
+               }
                // FIXME Do we really need to do this right before we delete d?
                // clear references to children in macro tables
                d->children_positions.clear();
@@ -453,8 +465,8 @@ Buffer::~Buffer()
 Buffer * Buffer::clone() const
 {
        BufferMap bufmap;
-       cloned_buffers.push_back(CloneList());
-       CloneList * clones = &cloned_buffers.back();
+       cloned_buffers.push_back(new CloneList());
+       CloneList * clones = cloned_buffers.back();
 
        masterBuffer()->clone(bufmap, clones);