[poppler] poppler/Page.cc poppler/Page.h poppler/PDFDoc.cc poppler/PDFDoc.h utils/HtmlOutputDev.cc utils/pdfinfo.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 29 23:17:36 UTC 2021


 poppler/PDFDoc.cc      |    4 ++--
 poppler/PDFDoc.h       |    2 +-
 poppler/Page.cc        |   14 +++++---------
 poppler/Page.h         |    4 ++--
 utils/HtmlOutputDev.cc |    3 +--
 utils/pdfinfo.cc       |    2 +-
 6 files changed, 12 insertions(+), 17 deletions(-)

New commits:
commit c66a781cac176a525a7d6e2042f50f89892a2f2a
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sat Oct 30 01:08:42 2021 +0200

    Make getLinks return a unique_ptr
    
    Fixes a leak in pdfinfo

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index f3ff38d1..53b44c59 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -663,11 +663,11 @@ void PDFDoc::displayPageSlice(OutputDev *out, int page, double hDPI, double vDPI
         getPage(page)->displaySlice(out, hDPI, vDPI, rotate, useMediaBox, crop, sliceX, sliceY, sliceW, sliceH, printing, abortCheckCbk, abortCheckCbkData, annotDisplayDecideCbk, annotDisplayDecideCbkData, copyXRef);
 }
 
-Links *PDFDoc::getLinks(int page)
+std::unique_ptr<Links> PDFDoc::getLinks(int page)
 {
     Page *p = getPage(page);
     if (!p) {
-        return new Links(nullptr);
+        return std::make_unique<Links>(nullptr);
     }
     return p->getLinks();
 }
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index aca23585..b1801aa4 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -210,7 +210,7 @@ public:
 
     // Returns the links for the current page, transferring ownership to
     // the caller.
-    Links *getLinks(int page);
+    std::unique_ptr<Links> getLinks(int page);
 
     // Find a named destination.  Returns the link destination, or
     // nullptr if <name> is not a destination.
diff --git a/poppler/Page.cc b/poppler/Page.cc
index cc6ad504..ae77d45b 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2005 Jeff Muizelaar <jeff at infidigm.net>
-// Copyright (C) 2005-2013, 2016-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2013, 2016-2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2006-2008 Pino Toscano <pino at kde.org>
 // Copyright (C) 2006 Nickolay V. Shmyrev <nshmyrev at yandex.ru>
 // Copyright (C) 2006 Scott Turner <scotty1024 at mac.com>
@@ -502,9 +502,9 @@ void Page::removeAnnot(Annot *annot)
     annot->setPage(0, false);
 }
 
-Links *Page::getLinks()
+std::unique_ptr<Links> Page::getLinks()
 {
-    return new Links(getAnnots());
+    return std::make_unique<Links>(getAnnots());
 }
 
 std::unique_ptr<FormPageWidgets> Page::getFormWidgets()
@@ -771,14 +771,10 @@ void Page::makeBox(double hDPI, double vDPI, int rotate, bool useMediaBox, bool
 
 void Page::processLinks(OutputDev *out)
 {
-    Links *links;
-    int i;
-
-    links = getLinks();
-    for (i = 0; i < links->getNumLinks(); ++i) {
+    std::unique_ptr<Links> links = getLinks();
+    for (int i = 0; i < links->getNumLinks(); ++i) {
         out->processLink(links->getLink(i));
     }
-    delete links;
 }
 
 void Page::getDefaultCTM(double *ctm, double hDPI, double vDPI, int rotate, bool useMediaBox, bool upsideDown)
diff --git a/poppler/Page.h b/poppler/Page.h
index 228e31e2..fbd2c16d 100644
--- a/poppler/Page.h
+++ b/poppler/Page.h
@@ -20,7 +20,7 @@
 // Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2008 Iñigo Martínez <inigomartinez at gmail.com>
 // Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
-// Copyright (C) 2012, 2017, 2018, 2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2012, 2017, 2018, 2020, 2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
@@ -186,7 +186,7 @@ public:
     void removeAnnot(Annot *annot);
 
     // Return a list of links.
-    Links *getLinks();
+    std::unique_ptr<Links> getLinks();
 
     // Return a list of annots. It will be valid until the page is destroyed
     Annots *getAnnots(XRef *xrefA = nullptr);
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 35d6776d..d49ccf9e 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -1228,11 +1228,10 @@ void HtmlOutputDev::startPage(int pageNumA, GfxState *state, XRef *xref)
 
 void HtmlOutputDev::endPage()
 {
-    Links *linksList = docPage->getLinks();
+    std::unique_ptr<Links> linksList = docPage->getLinks();
     for (int i = 0; i < linksList->getNumLinks(); ++i) {
         doProcessLink(linksList->getLink(i));
     }
-    delete linksList;
 
     pages->conv();
     pages->coalesce();
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 37cbbf22..9460ccb8 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -419,7 +419,7 @@ static void printUrlList(PDFDoc *doc)
     for (int pg = firstPage; pg <= lastPage; pg++) {
         Page *page = doc->getPage(pg);
         if (page) {
-            Links *links = page->getLinks();
+            std::unique_ptr<Links> links = page->getLinks();
             for (int i = 0; i < links->getNumLinks(); i++) {
                 AnnotLink *annot = links->getLink(i);
                 LinkAction *action = annot->getAction();


More information about the poppler mailing list