Valgrind "definitely lost" backtrace

Pavel Sanda sanda at lyx.org
Mon Feb 17 13:17:58 UTC 2020


On Sun, Feb 16, 2020 at 07:21:17PM -0500, Scott Kostyshak wrote:
> On Sat, Feb 15, 2020 at 09:42:52PM +0100, Pavel Sanda wrote:
> > On Fri, Feb 14, 2020 at 08:09:09PM -0500, Scott Kostyshak wrote:
> > > Thanks to both of you for taking a look. I was hoping to investigate
> > > this memory leak but it seems to be beyond my knowledge.
> > 
> > Do you have recipy to reproduce valgrind's warning?
> 
> 1. I run the following command (you will need to adapt it):
> 
>   valgrind --leak-check=full --track-origins=yes --log-file=valgrind.log ~/lyxbuilds/master/CMakeBuild/bin/lyx -userdir ~/lyxbuilds/master/user-dir
> 
> 2. Do "ctrl + n" to start a new document.
> 
> 3. Type "abc".
> 
> 4. Quit LyX and respond "no" when prompted whether to save the document.
> 
> I attach the full log in case it is useful. The other warnings involve
> external libraries.
> 
> Can anyone else reproduce?

I can reproduce. I looked now more carefully in the code, but couldn't
find where in the code are delete operators corresponding to the new operator
at TocModel.cpp:362.

So this looks like we just forget to free memory at the end of TocModels
life. As I know little about ToCXXX routines I would appreciate someone (Riki?)
knowing the context ack my change before comitting.

Pavel
-------------- next part --------------
diff --git a/src/frontends/qt/TocModel.cpp b/src/frontends/qt/TocModel.cpp
index 51365311aa..1519a6ac44 100644
--- a/src/frontends/qt/TocModel.cpp
+++ b/src/frontends/qt/TocModel.cpp
@@ -336,6 +336,13 @@ void TocModels::updateItem(QString const & type, DocIterator const & dit)
 	models_[type]->updateItem(dit);
 }
 
+TocModels::~TocModels(){
+	QHashIterator<QString, TocModel *> iter(models_);
+	while(iter.hasNext()) {
+		iter.next();
+		delete iter.value();
+	}
+}
 
 void TocModels::reset(BufferView const * bv)
 {
diff --git a/src/frontends/qt/TocModel.h b/src/frontends/qt/TocModel.h
index 8d336399c1..ad65cdc288 100644
--- a/src/frontends/qt/TocModel.h
+++ b/src/frontends/qt/TocModel.h
@@ -113,6 +113,7 @@ class TocModels : public QObject
 public:
 	///
 	TocModels();
+	~TocModels();
 	///
 	void reset(BufferView const * bv);
 	///


More information about the lyx-devel mailing list