Author: jghali
Date: Thu Mar  3 00:12:50 2022
New Revision: 24988

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

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

Modified: branches/Version15x/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24988&path=/branches/Version15x/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- branches/Version15x/Scribus/scribus/plugins/import/pdf/importpdf.cpp        
(original)
+++ branches/Version15x/Scribus/scribus/plugins/import/pdf/importpdf.cpp        
Thu Mar  3 00:12:50 2022
@@ -58,6 +58,7 @@
 #include "util.h"
 #include "util_formats.h"
 #include "util_math.h"
+#include "util_os.h"
 
 #include "ui/customfdialog.h"
 #include "ui/missing.h"
@@ -75,24 +76,21 @@
 
 QImage PdfPlug::readThumbnail(const QString& fName)
 {
-       QString pdfFile = QDir::toNativeSeparators(fName);
 #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 83, 0)
        globalParams.reset(new GlobalParams());
 #else
        std::unique_ptr<GlobalParams> globalParamsPtr(new GlobalParams());
        globalParams = globalParamsPtr.get();
 #endif
-
-#if defined(Q_OS_WIN32) && POPPLER_ENCODED_VERSION >= 
POPPLER_VERSION_ENCODE(0, 62, 0)
-       auto fname = new GooString(pdfFile.toUtf8().data());
+       globalParams->setErrQuiet(gTrue);
+
+       QString pdfFile = QDir::toNativeSeparators(fName);
+       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
-       globalParams->setErrQuiet(gTrue);
-
-#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)
@@ -339,17 +337,16 @@
        std::unique_ptr<GlobalParams> globalParamsPtr(new GlobalParams());
        globalParams = globalParamsPtr.get();
 #endif
-#if defined(Q_OS_WIN32) && POPPLER_ENCODED_VERSION >= 
POPPLER_VERSION_ENCODE(0, 62, 0)
-       auto fname = new GooString(fn.toUtf8().data());
+       globalParams->setErrQuiet(gTrue);
+
+
+       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
-       globalParams->setErrQuiet(gTrue);
-//     globalParams->setPrintCommands(gTrue);
-       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 fname = new GooString(encodedFileName.data());
        auto pdfDoc = std::unique_ptr<PDFDoc>(new PDFDoc(fname, nullptr, 
nullptr, nullptr));
 #endif
        if (pdfDoc)
@@ -365,15 +362,12 @@
                        QString text = QInputDialog::getText(mw, tr("Open 
PDF-File"), tr("Password"), QLineEdit::Normal, "", &ok);
                        if (ok && !text.isEmpty())
                        {
-#if defined(Q_OS_WIN32) && POPPLER_ENCODED_VERSION >= 
POPPLER_VERSION_ENCODE(0, 62, 0)
-                               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: branches/Version15x/Scribus/scribus/util_os.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24988&path=/branches/Version15x/Scribus/scribus/util_os.cpp
==============================================================================
--- branches/Version15x/Scribus/scribus/util_os.cpp     (original)
+++ branches/Version15x/Scribus/scribus/util_os.cpp     Thu Mar  3 00:12:50 2022
@@ -21,6 +21,8 @@
  ***************************************************************************/
 
 #include <QtGlobal>
+
+#include "util_os.h"
 
 bool os_is_osx()
 {


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to