Memory leak from list<CloneList *>

Scott Kostyshak skostysh at lyx.org
Sun Feb 23 13:23:19 UTC 2020


On Tue, Feb 18, 2020 at 08:28:33PM -0500, Scott Kostyshak wrote:
> On Tue, Feb 18, 2020 at 07:33:39PM -0500, Richard Kimberly Heck wrote:
> > On 2/18/20 6:07 PM, Scott Kostyshak wrote:
> > > Valgrind gave me the following error:
> > >
> > >   ==732== 112 (72 direct, 40 indirect) bytes in 1 blocks are definitely lost in loss record 5,165 of 5,862
> > >   ==732==    at 0x483AE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
> > >   ==732==    by 0x103A62D: lyx::Buffer::cloneBufferOnly() const (Buffer.cpp:661)
> > >   ==732==    by 0x11E583C: lyx::(anonymous namespace)::copyToTempBuffer(lyx::ParagraphList const&, std::shared_ptr<lyx::DocumentClass const>) (CutAndPaste.cpp:582)
> > >   ==732==    by 0x11E5C6A: lyx::(anonymous namespace)::putClipboard(lyx::ParagraphList const&, std::shared_ptr<lyx::DocumentClass const>, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, lyx::BufferParams) (CutAndPaste.cpp:613)
> > >   ==732==    by 0x11E910B: lyx::cap::copySelection(lyx::Cursor const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) (CutAndPaste.cpp:1123)
> > >   ==732==    by 0x11E84F8: lyx::cap::copySelection(lyx::Cursor const&) (CutAndPaste.cpp:1024)
> > >   ==732==    by 0x13ECDAB: lyx::Text::dispatch(lyx::Cursor&, lyx::FuncRequest&) (Text3.cpp:1593)
> > >   ==732==    by 0x1767E04: lyx::InsetText::doDispatch(lyx::Cursor&, lyx::FuncRequest&) (InsetText.cpp:339)
> > >   ==732==    by 0x15FFC39: lyx::Inset::dispatch(lyx::Cursor&, lyx::FuncRequest&) (Inset.cpp:325)
> > >   ==732==    by 0x11D1B13: lyx::Cursor::dispatch(lyx::FuncRequest const&) (Cursor.cpp:825)
> > >   ==732==    by 0x1816F4F: lyx::frontend::GuiView::dispatchToBufferView(lyx::FuncRequest const&, lyx::DispatchResult&) (GuiView.cpp:3878)
> > >   ==732==    by 0x181B959: lyx::frontend::GuiView::dispatch(lyx::FuncRequest const&, lyx::DispatchResult&) (GuiView.cpp:4569)
> > >
> > > It comes from the following line (Buffer.cpp:661):
> > >
> > >   cloned_buffers.push_back(new CloneList);
> > >
> > > Currently cloned_buffers is a list<CloneList *>. Would it make sense to make it a list of *smart* pointers instead? Alternatively we could make a class and then make a custom destructor that would free the CloneLists that the list elements point to?
> > 
> > This is some kind of thinko, probably on my part. The code at line 549
> > was supposed to be cleaning this up, but it actually only removes the
> > entry from the list.
> > 
> > If it works to make it a smart pointer of some kind, then that would be
> > simplest. But I think we could just do something like:
> > 
> > else {
> >     delete(*it);
> >     cloned_buffers.erase(it);
> > }
> 
> Ah that makes sense.

Riki, I propose that you commit. Thanks for the fix.

Scott
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20200223/1d12901f/attachment.asc>


More information about the lyx-devel mailing list