From c59c8ad9f06c531a858e744b46ec73f5df781694 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 21 Dec 2011 15:08:21 +0000 Subject: [PATCH] Add assertion to check for memory leaks and remove the list when we are done. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@40535 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e43a8cec76..7a08680807 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -144,7 +144,7 @@ void showPrintError(string const & name) // A storehouse for the cloned buffers. -list cloned_buffers; +list cloned_buffers; class Buffer::Impl @@ -410,6 +410,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::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(); @@ -450,8 +462,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); -- 2.39.5