r18649 by jghali - fix memory leak detected by Visual Leak Detector

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 15 19:00:37 UTC 2013


Author: jghali
Date: Sun Dec 15 19:00:36 2013
New Revision: 18649

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18649
Log:
fix memory leak detected by Visual Leak Detector

Modified:
    trunk/Scribus/scribus/nftrcreader.cpp
    trunk/Scribus/scribus/nfttemplate.cpp
    trunk/Scribus/scribus/nfttemplate.h

Modified: trunk/Scribus/scribus/nftrcreader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18649&path=/trunk/Scribus/scribus/nftrcreader.cpp
==============================================================================
--- trunk/Scribus/scribus/nftrcreader.cpp (original)
+++ trunk/Scribus/scribus/nftrcreader.cpp Sun Dec 15 19:00:36 2013
@@ -79,7 +79,7 @@
 				enCat = attrs.value(i);
 			}
 		}
-		tmpTemplate = new nfttemplate(new QFile(currentFile), category); // create a new template
+		tmpTemplate = new nfttemplate(currentFile, category); // create a new template
 		tmpTemplate->enCategory = enCat;
 	}
 
@@ -138,8 +138,15 @@
 	{ // new template starts here
 		inTemplate = false;
 		if (tmpTemplate != NULL) // If we have a template already created
+		{
 			if (tmpTemplate->isValid()) // and the template really exists push
 				templates->push_back(tmpTemplate); // it to the templates vector and start a new one
+			else
+			{
+				delete tmpTemplate;
+				tmpTemplate = 0;
+			}
+		}
 	}
 	if (inTemplate) {
 		if (inName && name == "name")

Modified: trunk/Scribus/scribus/nfttemplate.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18649&path=/trunk/Scribus/scribus/nfttemplate.cpp
==============================================================================
--- trunk/Scribus/scribus/nfttemplate.cpp (original)
+++ trunk/Scribus/scribus/nfttemplate.cpp Sun Dec 15 19:00:36 2013
@@ -10,25 +10,25 @@
 #include "nfttemplate.h"
 #include <QFileInfo>
 
-nfttemplate::nfttemplate(QFile* tmplXmlFile, const QString &tmplCategory) 
+nfttemplate::nfttemplate(QString tmplFilePath, const QString &tmplCategory)
+	: tmplXml(tmplFilePath)
 {
-	tmplXml = tmplXmlFile;
 	templateCategory = tmplCategory;
-	isWritable = tmplXml->open(QIODevice::WriteOnly | QIODevice::ReadOnly);
-	tmplXml->close();
+	isWritable = tmplXml.open(QIODevice::WriteOnly | QIODevice::ReadOnly);
+	tmplXml.close();
 	isDeleted = false;
 }
 
 void nfttemplate::remove()
 {
-	if (!tmplXml->exists())
+	if (!tmplXml.exists())
 		return;
 
 	QString newTmplXml = "";
 	QString tmp;
 	bool collect = false;
-	tmplXml->open(QIODevice::ReadOnly);
-	QTextStream stream(tmplXml);
+	tmplXml.open(QIODevice::ReadOnly);
+	QTextStream stream(&tmplXml);
 	stream.setCodec("UTF-8");
 	QString line = stream.readLine();
 	while (!line.isNull())
@@ -70,12 +70,12 @@
 		}
 		line = stream.readLine();
 	}
-	tmplXml->close();
-	tmplXml->open(QIODevice::WriteOnly);
-	QTextStream instream(tmplXml);
+	tmplXml.close();
+	tmplXml.open(QIODevice::WriteOnly);
+	QTextStream instream(&tmplXml);
 	instream.setCodec("UTF-8");
 	instream << newTmplXml;
-	tmplXml->close();
+	tmplXml.close();
 }
 
 bool nfttemplate::canWrite()

Modified: trunk/Scribus/scribus/nfttemplate.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18649&path=/trunk/Scribus/scribus/nfttemplate.h
==============================================================================
--- trunk/Scribus/scribus/nfttemplate.h (original)
+++ trunk/Scribus/scribus/nfttemplate.h Sun Dec 15 19:00:36 2013
@@ -16,9 +16,9 @@
 
 class nfttemplate {
 public:
-	nfttemplate(QFile* tmplXmlFile, const QString &tmplType);
+	nfttemplate(QString tmplFilePath, const QString &tmplType);
 	~nfttemplate();
-	QFile* tmplXml;
+	QFile   tmplXml;
 	QString enCategory;
 	QString templateCategory;
 	QString name;




More information about the scribus-commit mailing list