[poppler] glib/poppler-document.cc glib/poppler-page.cc poppler/Page.cc poppler/Page.h qt5/src qt6/src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Mar 14 18:29:30 UTC 2021


 glib/poppler-document.cc |    3 +--
 glib/poppler-page.cc     |    5 +----
 poppler/Page.cc          |    6 +++---
 poppler/Page.h           |    4 ++--
 qt5/src/poppler-page.cc  |    6 ++----
 qt6/src/poppler-page.cc  |    6 ++----
 6 files changed, 11 insertions(+), 19 deletions(-)

New commits:
commit e07f3e2e6a6df4ece88873ecbdbaf558f8910091
Author: Nelson Benítez León <nbenitezl at gmail.com>
Date:   Sat Mar 13 13:41:04 2021 -0400

    refactor Page::getFormWidgets() to use unique_ptr
    
    Refactor Page::getFormWidgets() to return
    std::unique_ptr<FormPageWidgets> so to avoid
    possible leaks in API users who forget
    to delete object.

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index bd26bc73..e8dfe137 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -3408,7 +3408,6 @@ PopplerFormField *poppler_document_get_form_field(PopplerDocument *document, gin
     Page *page;
     unsigned pageNum;
     unsigned fieldNum;
-    FormPageWidgets *widgets;
     FormWidget *field;
 
     FormWidget::decodeID(id, &pageNum, &fieldNum);
@@ -3417,7 +3416,7 @@ PopplerFormField *poppler_document_get_form_field(PopplerDocument *document, gin
     if (!page)
         return nullptr;
 
-    widgets = page->getFormWidgets();
+    const std::unique_ptr<FormPageWidgets> widgets = page->getFormWidgets();
     if (!widgets)
         return nullptr;
 
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 7e21c717..75c39c12 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1167,12 +1167,11 @@ void poppler_page_free_link_mapping(GList *list)
 GList *poppler_page_get_form_field_mapping(PopplerPage *page)
 {
     GList *map_list = nullptr;
-    FormPageWidgets *forms;
     gint i;
 
     g_return_val_if_fail(POPPLER_IS_PAGE(page), NULL);
 
-    forms = page->page->getFormWidgets();
+    const std::unique_ptr<FormPageWidgets> forms = page->page->getFormWidgets();
 
     if (forms == nullptr)
         return nullptr;
@@ -1196,8 +1195,6 @@ GList *poppler_page_get_form_field_mapping(PopplerPage *page)
         map_list = g_list_prepend(map_list, mapping);
     }
 
-    delete forms;
-
     return map_list;
 }
 
diff --git a/poppler/Page.cc b/poppler/Page.cc
index 7c16a131..cc6ad504 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -31,7 +31,7 @@
 // Copyright (C) 2015 Philipp Reinkemeier <philipp.reinkemeier at offis.de>
 // Copyright (C) 2018, 2019 Adam Reichold <adam.reichold at t-online.de>
 // Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
-// Copyright (C) 2020 Nelson Benítez León <nbenitezl at gmail.com>
+// Copyright (C) 2020, 2021 Nelson Benítez León <nbenitezl at gmail.com>
 // Copyright (C) 2020 Philipp Knechtges <philipp-dev at knechtges.com>
 //
 // To see a description of the changes please see the Changelog file that
@@ -507,9 +507,9 @@ Links *Page::getLinks()
     return new Links(getAnnots());
 }
 
-FormPageWidgets *Page::getFormWidgets()
+std::unique_ptr<FormPageWidgets> Page::getFormWidgets()
 {
-    FormPageWidgets *frmPageWidgets = new FormPageWidgets(getAnnots(), num, doc->getCatalog()->getForm());
+    auto frmPageWidgets = std::make_unique<FormPageWidgets>(getAnnots(), num, doc->getCatalog()->getForm());
     frmPageWidgets->addWidgets(standaloneFields, num);
 
     return frmPageWidgets;
diff --git a/poppler/Page.h b/poppler/Page.h
index 68126306..4f8a3d3d 100644
--- a/poppler/Page.h
+++ b/poppler/Page.h
@@ -25,7 +25,7 @@
 // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
 // Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
-// Copyright (C) 2020 Nelson Benítez León <nbenitezl at gmail.com>
+// Copyright (C) 2020, 2021 Nelson Benítez León <nbenitezl at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -202,7 +202,7 @@ public:
     Object getTrans() { return trans.fetch(xref); }
 
     // Get form.
-    FormPageWidgets *getFormWidgets();
+    std::unique_ptr<FormPageWidgets> getFormWidgets();
 
     // Get duration, the maximum length of time, in seconds,
     // that the page is displayed before the presentation automatically
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index 31c60698..9f681722 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -22,7 +22,7 @@
  * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
  * Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
  * Copyright (C) 2018, Tobias Deiminger <haxtibal at posteo.de>
- * Copyright (C) 2018 Nelson Benítez León <nbenitezl at gmail.com>
+ * Copyright (C) 2018, 2021 Nelson Benítez León <nbenitezl at gmail.com>
  * Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2020 Philipp Knechtges <philipp-dev at knechtges.com>
  *
@@ -862,7 +862,7 @@ QList<FormField *> Page::formFields() const
 {
     QList<FormField *> fields;
     ::Page *p = m_page->page;
-    ::FormPageWidgets *form = p->getFormWidgets();
+    const std::unique_ptr<FormPageWidgets> form = p->getFormWidgets();
     int formcount = form->getNumWidgets();
     for (int i = 0; i < formcount; ++i) {
         ::FormWidget *fm = form->getWidget(i);
@@ -891,8 +891,6 @@ QList<FormField *> Page::formFields() const
             fields.append(ff);
     }
 
-    delete form;
-
     return fields;
 }
 
diff --git a/qt6/src/poppler-page.cc b/qt6/src/poppler-page.cc
index 248b48d5..0ad6c013 100644
--- a/qt6/src/poppler-page.cc
+++ b/qt6/src/poppler-page.cc
@@ -22,7 +22,7 @@
  * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
  * Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
  * Copyright (C) 2018, Tobias Deiminger <haxtibal at posteo.de>
- * Copyright (C) 2018 Nelson Benítez León <nbenitezl at gmail.com>
+ * Copyright (C) 2018, 2021 Nelson Benítez León <nbenitezl at gmail.com>
  * Copyright (C) 2020 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2020 Philipp Knechtges <philipp-dev at knechtges.com>
  *
@@ -834,7 +834,7 @@ QList<FormField *> Page::formFields() const
 {
     QList<FormField *> fields;
     ::Page *p = m_page->page;
-    ::FormPageWidgets *form = p->getFormWidgets();
+    const std::unique_ptr<FormPageWidgets> form = p->getFormWidgets();
     int formcount = form->getNumWidgets();
     for (int i = 0; i < formcount; ++i) {
         ::FormWidget *fm = form->getWidget(i);
@@ -863,8 +863,6 @@ QList<FormField *> Page::formFields() const
             fields.append(ff);
     }
 
-    delete form;
-
     return fields;
 }
 


More information about the poppler mailing list