cpp/poppler-document-private.h | 4 ++-- cpp/poppler-document.cpp | 8 ++++---- glib/poppler-document.cc | 7 ++----- poppler/CurlPDFDocBuilder.cc | 4 ++-- poppler/Form.cc | 9 ++++----- poppler/Form.h | 2 +- poppler/LocalPDFDocBuilder.cc | 9 ++++----- poppler/PDFDoc.cc | 16 ++++++++-------- poppler/PDFDoc.h | 8 ++++---- poppler/PDFDocFactory.cc | 5 ++--- qt5/src/poppler-private.h | 3 +-- qt5/tests/check_optcontent.cpp | 6 ++---- qt6/src/poppler-private.h | 3 +-- qt6/tests/check_optcontent.cpp | 6 ++---- test/pdf-fullrewrite.cc | 13 +++---------- test/pdf-inspector.cc | 7 ++----- test/perf-test.cc | 16 +++------------- utils/pdfseparate.cc | 5 ++--- utils/pdfunite.cc | 5 ++--- 19 files changed, 51 insertions(+), 85 deletions(-)
New commits: commit 07889cdfd8a261dc5ae6eb72c26a8a3ec2e35930 Author: Albert Astals Cid <[email protected]> Date: Tue Feb 15 17:14:44 2022 +0100 Make PDFDoc constructor take the filename as unique_ptr Makes it clear that it will own the given GooString diff --git a/cpp/poppler-document-private.h b/cpp/poppler-document-private.h index e67072b6..2f662204 100644 --- a/cpp/poppler-document-private.h +++ b/cpp/poppler-document-private.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2009-2011, Pino Toscano <[email protected]> - * Copyright (C) 2018, 2020, Albert Astals Cid <[email protected]> + * Copyright (C) 2018, 2020, 2022, Albert Astals Cid <[email protected]> * Copyright (C) 2018, 2020, Adam Reichold <[email protected]> * * This program is free software; you can redistribute it and/or modify @@ -38,7 +38,7 @@ class embedded_file; class document_private : private GlobalParamsIniter { public: - document_private(GooString *file_path, const std::string &owner_password, const std::string &user_password); + document_private(std::unique_ptr<GooString> &&file_path, const std::string &owner_password, const std::string &user_password); document_private(byte_array *file_data, const std::string &owner_password, const std::string &user_password); document_private(const char *file_data, int file_data_length, const std::string &owner_password, const std::string &user_password); ~document_private(); diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp index 2dd47921..c134c5f8 100644 --- a/cpp/poppler-document.cpp +++ b/cpp/poppler-document.cpp @@ -50,11 +50,11 @@ using namespace poppler; -document_private::document_private(GooString *file_path, const std::string &owner_password, const std::string &user_password) : document_private() +document_private::document_private(std::unique_ptr<GooString> &&file_path, const std::string &owner_password, const std::string &user_password) : document_private() { GooString goo_owner_password(owner_password.c_str()); GooString goo_user_password(user_password.c_str()); - doc = new PDFDoc(file_path, &goo_owner_password, &goo_user_password); + doc = new PDFDoc(std::move(file_path), &goo_owner_password, &goo_user_password); } document_private::document_private(byte_array *file_data, const std::string &owner_password, const std::string &user_password) : document_private() @@ -176,7 +176,7 @@ bool document::unlock(const std::string &owner_password, const std::string &user } else if (d->raw_doc_data) { newdoc = new document_private(d->raw_doc_data, d->raw_doc_data_length, owner_password, user_password); } else { - newdoc = new document_private(new GooString(d->doc->getFileName()), owner_password, user_password); + newdoc = new document_private(std::make_unique<GooString>(d->doc->getFileName()), owner_password, user_password); } if (!newdoc->doc->isOk()) { d->doc_data.swap(newdoc->doc_data); @@ -1052,7 +1052,7 @@ bool document::save_a_copy(const std::string &file_name) const */ document *document::load_from_file(const std::string &file_name, const std::string &owner_password, const std::string &user_password) { - document_private *doc = new document_private(new GooString(file_name.c_str()), owner_password, user_password); + document_private *doc = new document_private(std::make_unique<GooString>(file_name.c_str()), owner_password, user_password); return document_private::check_document(doc, nullptr); } diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index 29172833..00991937 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -222,16 +222,13 @@ PopplerDocument *poppler_document_new_from_file(const char *uri, const char *pas } delete[] filenameW; #else - GooString *filename_g; - filename_g = new GooString(filename); - newDoc = new PDFDoc(filename_g, password_g, password_g); + newDoc = new PDFDoc(std::make_unique<GooString>(filename), password_g, password_g); if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) { /* Try again with original password (which comes from GTK in UTF8) Issue #824 */ - filename_g = filename_g->copy(); delete newDoc; delete password_g; password_g = new GooString(password); - newDoc = new PDFDoc(filename_g, password_g, password_g); + newDoc = new PDFDoc(std::make_unique<GooString>(filename), password_g, password_g); } #endif g_free(filename); diff --git a/poppler/CurlPDFDocBuilder.cc b/poppler/CurlPDFDocBuilder.cc index 367a5b4f..70e5a703 100644 --- a/poppler/CurlPDFDocBuilder.cc +++ b/poppler/CurlPDFDocBuilder.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright 2010 Hib Eris <[email protected]> -// Copyright 2010, 2017 Albert Astals Cid <[email protected]> +// Copyright 2010, 2017, 2022 Albert Astals Cid <[email protected]> // Copyright 2021 Oliver Sander <[email protected]> // //======================================================================== @@ -28,7 +28,7 @@ std::unique_ptr<PDFDoc> CurlPDFDocBuilder::buildPDFDoc(const GooString &uri, Goo if (cachedFile->getLength() == ((unsigned int)-1)) { cachedFile->decRefCnt(); - return PDFDoc::ErrorPDFDoc(errOpenFile, uri.copy()); + return PDFDoc::ErrorPDFDoc(errOpenFile, std::unique_ptr<GooString>(uri.copy())); } BaseStream *str = new CachedFileStream(cachedFile, 0, false, cachedFile->getLength(), Object(objNull)); diff --git a/poppler/Form.cc b/poppler/Form.cc index d0f4bcc8..139e9392 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -604,10 +604,9 @@ bool FormWidgetSignature::signDocument(const char *saveFilename, const char *cer } // Incremental save to avoid breaking any existing signatures - GooString *fname = new GooString(saveFilename); - if (doc->saveAs(*fname, writeForceIncremental) != errNone) { + const GooString fname(saveFilename); + if (doc->saveAs(fname, writeForceIncremental) != errNone) { fprintf(stderr, "signDocument: error saving to file \"%s\"\n", saveFilename); - delete fname; return false; } @@ -704,9 +703,9 @@ bool FormWidgetSignature::signDocumentWithAppearance(const char *saveFilename, c } // Get start and end file position of objNum in the PDF named filename. -bool FormWidgetSignature::getObjectStartEnd(GooString *filename, int objNum, Goffset *objStart, Goffset *objEnd, const GooString *ownerPassword, const GooString *userPassword) +bool FormWidgetSignature::getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const GooString *ownerPassword, const GooString *userPassword) { - PDFDoc newDoc(filename, ownerPassword, userPassword); + PDFDoc newDoc(std::unique_ptr<GooString>(filename.copy()), ownerPassword, userPassword); if (!newDoc.isOk()) return false; diff --git a/poppler/Form.h b/poppler/Form.h index cef04150..5d3c931f 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -329,7 +329,7 @@ public: private: bool createSignature(Object &vObj, Ref vRef, const GooString &name, const GooString *signature, const GooString *reason = nullptr, const GooString *location = nullptr); - bool getObjectStartEnd(GooString *filename, int objNum, Goffset *objStart, Goffset *objEnd, const GooString *ownerPassword, const GooString *userPassword); + bool getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const GooString *ownerPassword, const GooString *userPassword); bool updateOffsets(FILE *f, Goffset objStart, Goffset objEnd, Goffset *sigStart, Goffset *sigEnd, Goffset *fileSize); bool updateSignature(FILE *f, Goffset sigStart, Goffset sigEnd, const GooString *signature); diff --git a/poppler/LocalPDFDocBuilder.cc b/poppler/LocalPDFDocBuilder.cc index 9aab08eb..bd78041d 100644 --- a/poppler/LocalPDFDocBuilder.cc +++ b/poppler/LocalPDFDocBuilder.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright 2010 Hib Eris <[email protected]> -// Copyright 2010 Albert Astals Cid <[email protected]> +// Copyright 2010, 2022 Albert Astals Cid <[email protected]> // Copyright 2021 Oliver Sander <[email protected]> // //======================================================================== @@ -21,12 +21,11 @@ std::unique_ptr<PDFDoc> LocalPDFDocBuilder::buildPDFDoc(const GooString &uri, GooString *ownerPassword, GooString *userPassword, void *guiDataA) { if (uri.cmpN("file://", 7) == 0) { - GooString *fileName = uri.copy(); + std::unique_ptr<GooString> fileName(uri.copy()); fileName->del(0, 7); - return std::make_unique<PDFDoc>(fileName, ownerPassword, userPassword, guiDataA); + return std::make_unique<PDFDoc>(std::move(fileName), ownerPassword, userPassword, guiDataA); } else { - GooString *fileName = uri.copy(); - return std::make_unique<PDFDoc>(fileName, ownerPassword, userPassword, guiDataA); + return std::make_unique<PDFDoc>(std::unique_ptr<GooString>(uri.copy()), ownerPassword, userPassword, guiDataA); } } diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index 44163450..71d28603 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -121,7 +121,8 @@ PDFDoc::PDFDoc() { } -PDFDoc::PDFDoc(const GooString *fileNameA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : fileName(fileNameA), guiData(guiDataA) +PDFDoc::PDFDoc(std::unique_ptr<GooString> &&fileNameA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) + : fileName(std::move(fileNameA)), guiData(guiDataA) { #ifdef _WIN32 const int n = fileName->getLength(); @@ -143,7 +144,7 @@ PDFDoc::PDFDoc(const GooString *fileNameA, const GooString *ownerPassword, const // Keep a copy of the errno returned by fopen so that it can be // referred to later. fopenErrno = errno; - error(errIO, -1, "Couldn't open file '{0:t}': {1:s}.", fileName, strerror(errno)); + error(errIO, -1, "Couldn't open file '{0:t}': {1:s}.", fileName.get(), strerror(errno)); errCode = errOpenFile; return; } @@ -166,7 +167,7 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, Go fileNameG->append((char)fileNameA[i]); fileNameU[i] = fileNameA[i]; } - fileName = fileNameG; + fileName.reset(fileNameG); fileNameU[fileNameLen] = L'\0'; // try to open file @@ -179,7 +180,7 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, Go file = GooFile::open(fileName->toStr()); } if (!file) { - error(errIO, -1, "Couldn't open file '{0:t}'", fileName); + error(errIO, -1, "Couldn't open file '{0:t}'", fileName.get()); errCode = errOpenFile; return; } @@ -194,7 +195,7 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, Go PDFDoc::PDFDoc(BaseStream *strA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA) { if (strA->getFileName()) { - fileName = strA->getFileName()->copy(); + fileName.reset(strA->getFileName()->copy()); #ifdef _WIN32 const int n = fileName->getLength(); fileNameU = (wchar_t *)gmallocn(n + 1, sizeof(wchar_t)); @@ -300,7 +301,6 @@ PDFDoc::~PDFDoc() delete linearization; delete str; delete file; - delete fileName; #ifdef _WIN32 gfree(fileNameU); #endif @@ -1896,12 +1896,12 @@ Outline *PDFDoc::getOutline() return outline; } -std::unique_ptr<PDFDoc> PDFDoc::ErrorPDFDoc(int errorCode, const GooString *fileNameA) +std::unique_ptr<PDFDoc> PDFDoc::ErrorPDFDoc(int errorCode, std::unique_ptr<GooString> &&fileNameA) { // We cannot call std::make_unique here because the PDFDoc constructor is private PDFDoc *doc = new PDFDoc(); doc->errCode = errorCode; - doc->fileName = fileNameA; + doc->fileName = std::move(fileNameA); return std::unique_ptr<PDFDoc>(doc); } diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h index 3128674a..5ca5b8da 100644 --- a/poppler/PDFDoc.h +++ b/poppler/PDFDoc.h @@ -129,7 +129,7 @@ enum PDFSubtypeConformance class POPPLER_PRIVATE_EXPORT PDFDoc { public: - explicit PDFDoc(const GooString *fileNameA, const GooString *ownerPassword = nullptr, const GooString *userPassword = nullptr, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {}); + explicit PDFDoc(std::unique_ptr<GooString> &&fileNameA, const GooString *ownerPassword = nullptr, const GooString *userPassword = nullptr, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {}); #ifdef _WIN32 PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {}); @@ -141,7 +141,7 @@ public: PDFDoc(const PDFDoc &) = delete; PDFDoc &operator=(const PDFDoc &) = delete; - static std::unique_ptr<PDFDoc> ErrorPDFDoc(int errorCode, const GooString *fileNameA = nullptr); + static std::unique_ptr<PDFDoc> ErrorPDFDoc(int errorCode, std::unique_ptr<GooString> &&fileNameA); // Was PDF document successfully opened? bool isOk() const { return ok; } @@ -154,7 +154,7 @@ public: int getFopenErrno() const { return fopenErrno; } // Get file name. - const GooString *getFileName() const { return fileName; } + const GooString *getFileName() const { return fileName.get(); } #ifdef _WIN32 wchar_t *getFileNameU() { return fileNameU; } #endif @@ -381,7 +381,7 @@ private: Goffset getMainXRefEntriesOffset(bool tryingToReconstruct = false); long long strToLongLong(const char *s); - const GooString *fileName = nullptr; + std::unique_ptr<GooString> fileName; #ifdef _WIN32 wchar_t *fileNameU = nullptr; #endif diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc index 50c953e8..9e665977 100644 --- a/poppler/PDFDocFactory.cc +++ b/poppler/PDFDocFactory.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright 2010 Hib Eris <[email protected]> -// Copyright 2010 Albert Astals Cid <[email protected]> +// Copyright 2010, 2022 Albert Astals Cid <[email protected]> // Copyright 2017 Adrian Johnson <[email protected]> // Copyright 2018 Adam Reichold <[email protected]> // Copyright 2019, 2021 Oliver Sander <[email protected]> @@ -64,8 +64,7 @@ std::unique_ptr<PDFDoc> PDFDocFactory::createPDFDoc(const GooString &uri, GooStr } error(errInternal, -1, "Cannot handle URI '{0:t}'.", &uri); - GooString *fileName = uri.copy(); - return PDFDoc::ErrorPDFDoc(errOpenFile, fileName); + return PDFDoc::ErrorPDFDoc(errOpenFile, std::unique_ptr<GooString>(uri.copy())); } void PDFDocFactory::registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder) diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h index 19029953..83940dcc 100644 --- a/qt5/src/poppler-private.h +++ b/qt5/src/poppler-private.h @@ -113,8 +113,7 @@ public: #ifdef _WIN32 doc = new PDFDoc((wchar_t *)filePath.utf16(), filePath.length(), ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this)); #else - GooString *fileName = new GooString(QFile::encodeName(filePath).constData()); - doc = new PDFDoc(fileName, ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this)); + doc = new PDFDoc(std::make_unique<GooString>(QFile::encodeName(filePath).constData()), ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this)); #endif delete ownerPassword; diff --git a/qt5/tests/check_optcontent.cpp b/qt5/tests/check_optcontent.cpp index bb267e92..b254cdb1 100644 --- a/qt5/tests/check_optcontent.cpp +++ b/qt5/tests/check_optcontent.cpp @@ -88,9 +88,8 @@ void TestOptionalContent::checkNoOptionalContent() void TestOptionalContent::checkIsVisible() { - GooString *fileName = new GooString(TESTDATADIR "/unittestcases/vis_policy_test.pdf"); globalParams = std::make_unique<GlobalParams>(); - PDFDoc *doc = new PDFDoc(fileName); + PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(TESTDATADIR "/unittestcases/vis_policy_test.pdf")); QVERIFY(doc); OCGs *ocgs = doc->getOptContentConfig(); @@ -162,8 +161,7 @@ void TestOptionalContent::checkIsVisible() void TestOptionalContent::checkVisibilitySetting() { globalParams = std::make_unique<GlobalParams>(); - GooString *fileName = new GooString(TESTDATADIR "/unittestcases/vis_policy_test.pdf"); - PDFDoc *doc = new PDFDoc(fileName); + PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(TESTDATADIR "/unittestcases/vis_policy_test.pdf")); QVERIFY(doc); OCGs *ocgs = doc->getOptContentConfig(); diff --git a/qt6/src/poppler-private.h b/qt6/src/poppler-private.h index b2af88cd..1f1ebb17 100644 --- a/qt6/src/poppler-private.h +++ b/qt6/src/poppler-private.h @@ -112,8 +112,7 @@ public: #ifdef _WIN32 doc = new PDFDoc((wchar_t *)filePath.utf16(), filePath.length(), ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this)); #else - GooString *fileName = new GooString(QFile::encodeName(filePath).constData()); - doc = new PDFDoc(fileName, ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this)); + doc = new PDFDoc(std::make_unique<GooString>(QFile::encodeName(filePath).constData()), ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this)); #endif delete ownerPassword; diff --git a/qt6/tests/check_optcontent.cpp b/qt6/tests/check_optcontent.cpp index b5956682..5f9294bc 100644 --- a/qt6/tests/check_optcontent.cpp +++ b/qt6/tests/check_optcontent.cpp @@ -79,9 +79,8 @@ void TestOptionalContent::checkNoOptionalContent() void TestOptionalContent::checkIsVisible() { - GooString *fileName = new GooString(TESTDATADIR "/unittestcases/vis_policy_test.pdf"); globalParams = std::make_unique<GlobalParams>(); - PDFDoc *doc = new PDFDoc(fileName); + PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(TESTDATADIR "/unittestcases/vis_policy_test.pdf")); QVERIFY(doc); OCGs *ocgs = doc->getOptContentConfig(); @@ -153,8 +152,7 @@ void TestOptionalContent::checkIsVisible() void TestOptionalContent::checkVisibilitySetting() { globalParams = std::make_unique<GlobalParams>(); - GooString *fileName = new GooString(TESTDATADIR "/unittestcases/vis_policy_test.pdf"); - PDFDoc *doc = new PDFDoc(fileName); + PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(TESTDATADIR "/unittestcases/vis_policy_test.pdf")); QVERIFY(doc); OCGs *ocgs = doc->getOptContentConfig(); diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc index 1afc7e16..4c8d9818 100644 --- a/test/pdf-fullrewrite.cc +++ b/test/pdf-fullrewrite.cc @@ -39,8 +39,6 @@ int main(int argc, char *argv[]) { PDFDoc *doc = nullptr; PDFDoc *docOut = nullptr; - GooString *inputName = nullptr; - GooString *outputName = nullptr; GooString *ownerPW = nullptr; GooString *userPW = nullptr; int res = 0; @@ -55,9 +53,6 @@ int main(int argc, char *argv[]) goto done; } - inputName = new GooString(argv[1]); - outputName = new GooString(argv[2]); - if (ownerPassword[0] != '\001') { ownerPW = new GooString(ownerPassword); } @@ -67,7 +62,7 @@ int main(int argc, char *argv[]) // load input document globalParams = std::make_unique<GlobalParams>(); - doc = new PDFDoc(inputName, ownerPW, userPW); + doc = new PDFDoc(std::make_unique<GooString>(argv[1]), ownerPW, userPW); if (!doc->isOk()) { fprintf(stderr, "Error loading input document\n"); res = 1; @@ -75,7 +70,7 @@ int main(int argc, char *argv[]) } // save it back (in rewrite or incremental update mode) - if (doc->saveAs(*outputName, forceIncremental ? writeForceIncremental : writeForceRewrite) != 0) { + if (doc->saveAs(*doc->getFileName(), forceIncremental ? writeForceIncremental : writeForceRewrite) != 0) { fprintf(stderr, "Error saving document\n"); res = 1; goto done; @@ -83,7 +78,7 @@ int main(int argc, char *argv[]) if (checkOutput) { // open the generated document to verify it - docOut = new PDFDoc(outputName, ownerPW, userPW); + docOut = new PDFDoc(std::make_unique<GooString>(argv[2]), ownerPW, userPW); if (!docOut->isOk()) { fprintf(stderr, "Error loading generated document\n"); res = 1; @@ -91,8 +86,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "Verification failed\n"); res = 1; } - } else { - delete outputName; } done: diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc index eb6c62e1..f3034cf1 100644 --- a/test/pdf-inspector.cc +++ b/test/pdf-inspector.cc @@ -4,7 +4,7 @@ // // Copyright 2005 Jonathan Blandford <[email protected]> // Copyright 2018 Adam Reichold <[email protected]> -// Copyright 2019 Albert Astals Cid <[email protected]> +// Copyright 2019, 2022 Albert Astals Cid <[email protected]> // //======================================================================== @@ -222,10 +222,7 @@ void PdfInspector::load(const char *file_name) // load the new file if (file_name) { - GooString *filename_g; - - filename_g = new GooString(file_name); - doc = new PDFDoc(filename_g, nullptr, nullptr); + doc = new PDFDoc(std::make_unique<GooString>(file_name), nullptr, nullptr); } if (doc && !doc->isOk()) { diff --git a/test/perf-test.cc b/test/perf-test.cc index 36e21bb0..1d577eb1 100644 --- a/test/perf-test.cc +++ b/test/perf-test.cc @@ -1,6 +1,6 @@ /* Copyright Krzysztof Kowalczyk 2006-2007 Copyright Hib Eris <[email protected]> 2008, 2013 - Copyright 2018, 2020 Albert Astals Cid <[email protected]> 2018 + Copyright 2018, 2020, 2022 Albert Astals Cid <[email protected]> 2018 Copyright 2019 Oliver Sander <[email protected]> Copyright 2020 Adam Reichold <[email protected]> License: GPLv2 */ @@ -382,12 +382,8 @@ PdfEnginePoppler::~PdfEnginePoppler() bool PdfEnginePoppler::load(const char *fileName) { setFileName(fileName); - /* note: don't delete fileNameStr since PDFDoc takes ownership and deletes them itself */ - GooString *fileNameStr = new GooString(fileName); - if (!fileNameStr) - return false; - _pdfDoc = new PDFDoc(fileNameStr, nullptr, nullptr, nullptr); + _pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName), nullptr, nullptr, nullptr); if (!_pdfDoc->isOk()) { return false; } @@ -585,7 +581,6 @@ static bool ShowPreview() static void RenderPdfAsText(const char *fileName) { - GooString *fileNameStr = nullptr; PDFDoc *pdfDoc = nullptr; GooString *txt = nullptr; int pageCount; @@ -604,12 +599,7 @@ static void RenderPdfAsText(const char *fileName) } GooTimer msTimer; - /* note: don't delete fileNameStr since PDFDoc takes ownership and deletes them itself */ - fileNameStr = new GooString(fileName); - if (!fileNameStr) - goto Exit; - - pdfDoc = new PDFDoc(fileNameStr, nullptr, nullptr, nullptr); + pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName), nullptr, nullptr, nullptr); if (!pdfDoc->isOk()) { error(errIO, -1, "RenderPdfFile(): failed to open PDF file {0:s}\n", fileName); goto Exit; diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc index c0c84bb4..40afe530 100644 --- a/utils/pdfseparate.cc +++ b/utils/pdfseparate.cc @@ -46,8 +46,7 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to static bool extractPages(const char *srcFileName, const char *destFileName) { char pathName[4096]; - GooString *gfileName = new GooString(srcFileName); - PDFDoc *doc = new PDFDoc(gfileName, nullptr, nullptr, nullptr); + PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(srcFileName), nullptr, nullptr, nullptr); if (!doc->isOk()) { error(errSyntaxError, -1, "Could not extract page(s) from damaged file ('{0:s}')", srcFileName); @@ -118,7 +117,7 @@ static bool extractPages(const char *srcFileName, const char *destFileName) for (int pageNo = firstPage; pageNo <= lastPage; pageNo++) { snprintf(pathName, sizeof(pathName) - 1, destFileName, pageNo); - PDFDoc *pagedoc = new PDFDoc(new GooString(srcFileName), nullptr, nullptr, nullptr); + PDFDoc *pagedoc = new PDFDoc(std::make_unique<GooString>(srcFileName), nullptr, nullptr, nullptr); int errCode = pagedoc->savePageAs(GooString(pathName), pageNo); if (errCode != errNone) { delete doc; diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc index 1203de0e..4731eed7 100644 --- a/utils/pdfunite.cc +++ b/utils/pdfunite.cc @@ -7,7 +7,7 @@ // Copyright (C) 2011-2015, 2017 Thomas Freitag <[email protected]> // Copyright (C) 2012 Arseny Solokha <[email protected]> // Copyright (C) 2012 Fabio D'Urso <[email protected]> -// Copyright (C) 2012, 2014, 2017-2019, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2012, 2014, 2017-2019, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2013 Adrian Johnson <[email protected]> // Copyright (C) 2013 Hib Eris <[email protected]> // Copyright (C) 2015 Arthur Stavisky <[email protected]> @@ -154,8 +154,7 @@ int main(int argc, char *argv[]) globalParams = std::make_unique<GlobalParams>(); for (i = 1; i < argc - 1; i++) { - GooString *gfileName = new GooString(argv[i]); - PDFDoc *doc = new PDFDoc(gfileName, nullptr, nullptr, nullptr); + PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(argv[i]), nullptr, nullptr, nullptr); if (doc->isOk() && !doc->isEncrypted() && doc->getXRef()->getCatalog().isDict()) { docs.push_back(doc); if (doc->getPDFMajorVersion() > majorVersion) {
