r24989 by jghali - #16764: Better patch, avoid a memory leak

scribus-commit scribus-commit at lists.scribus.net
Thu Mar 3 00:18:06 UTC 2022


Author: jghali
Date: Thu Mar  3 00:18:06 2022
New Revision: 24989

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24989
Log:
#16764: Better patch, avoid a memory leak

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
    trunk/Scribus/scribus/util_os.cpp

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24989&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp	Thu Mar  3 00:18:06 2022
@@ -57,6 +57,7 @@
 #include "util.h"
 #include "util_formats.h"
 #include "util_math.h"
+#include "util_os.h"
 
 #include "ui/customfdialog.h"
 #include "ui/missing.h"
@@ -78,15 +79,12 @@
 	globalParams->setErrQuiet(gTrue);
 
 	QString pdfFile = QDir::toNativeSeparators(fName);
-#if defined(Q_OS_WIN32)
-	auto fname = new GooString(pdfFile.toUtf8().data());
+	QByteArray encodedFileName = os_is_win() ? pdfFile.toUtf8() : QFile::encodeName(pdfFile);
+#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 3, 0)
+	auto fname = std::make_unique<GooString>(encodedFileName.data());
+	PDFDoc pdfDoc{ std::move(fname) };
 #else
-	auto fname = new GooString(QFile::encodeName(pdfFile).data());
-#endif
-
-#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 3, 0)
-	PDFDoc pdfDoc{ std::make_unique<GooString>(fname) };
-#else
+	auto fname = new GooString(encodedFileName.data());
 	PDFDoc pdfDoc{fname, nullptr, nullptr, nullptr};
 #endif
 	if (!pdfDoc.isOk() || pdfDoc.getErrorCode() == errEncrypted)
@@ -330,17 +328,14 @@
 	globalParams.reset(new GlobalParams());
 	globalParams->setErrQuiet(gTrue);
 
-#if defined(Q_OS_WIN32)
-	auto fname = new GooString(fn.toUtf8().data());
+	QList<OptionalContentGroup*> ocgGroups;
+	QByteArray encodedFileName = os_is_win() ? fn.toUtf8() : QFile::encodeName(fn);
+#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 3, 0)
+	auto fname = std::make_unique<GooString>(encodedFileName.data());
+	auto pdfDoc = std::make_unique<PDFDoc>(std::move(fname));
 #else
-	auto fname = new GooString(QFile::encodeName(fn).data());
-#endif
-
-	QList<OptionalContentGroup*> ocgGroups;
-#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 3, 0)
-	auto pdfDoc = std::make_unique<PDFDoc>(std::make_unique<GooString>(fname));
-#else
-	auto pdfDoc = std::unique_ptr<PDFDoc>(new PDFDoc(fname, nullptr, nullptr, nullptr));
+	auto fname = new GooString(encodedFileName.data());
+	auto pdfDoc = std::make_unique<PDFDoc>(fname, nullptr, nullptr, nullptr);
 #endif
 	if (pdfDoc)
 	{
@@ -355,15 +350,12 @@
 			QString text = QInputDialog::getText(mw, tr("Open PDF-File"), tr("Password"), QLineEdit::Normal, "", &ok);
 			if (ok && !text.isEmpty())
 			{
-#if defined(Q_OS_WIN32)
-				auto fname = new GooString(fn.toUtf8().data());
+#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 3, 0)
+				auto fname = std::make_unique<GooString>(encodedFileName.data());
+				std::optional<GooString> userPW(std::in_place, text.toLocal8Bit().data());
+				pdfDoc.reset(new PDFDoc(std::move(fname), userPW, userPW, nullptr));
 #else
-				auto fname = new GooString(QFile::encodeName(fn).data());
-#endif
-#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 3, 0)
-				std::optional<GooString> userPW(std::in_place, text.toLocal8Bit().data());
-				pdfDoc.reset(new PDFDoc(std::make_unique<GooString>(fname), userPW, userPW, nullptr));
-#else
+				auto fname = new GooString(encodedFileName.data());
 				auto userPW = new GooString(text.toLocal8Bit().data());
 				pdfDoc.reset(new PDFDoc(fname, userPW, userPW, nullptr));
 #endif

Modified: trunk/Scribus/scribus/util_os.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24989&path=/trunk/Scribus/scribus/util_os.cpp
==============================================================================
--- trunk/Scribus/scribus/util_os.cpp	(original)
+++ trunk/Scribus/scribus/util_os.cpp	Thu Mar  3 00:18:06 2022
@@ -21,6 +21,8 @@
  ***************************************************************************/
 
 #include <QtGlobal>
+
+#include "util_os.h"
 
 bool os_is_osx()
 {




More information about the scribus-commit mailing list