goo/gdir.h              |    6 ++++--
 goo/gfile.cc            |   13 ++++++-------
 poppler/GlobalParams.cc |    8 ++------
 3 files changed, 12 insertions(+), 15 deletions(-)

New commits:
commit ee974518464914b0e52549044a244863fd4342f7
Author: Albert Astals Cid <aa...@kde.org>
Date:   Mon Jan 17 15:55:57 2022 +0100

    Make GDir::getNextEntry return a unique pointer

diff --git a/goo/gdir.h b/goo/gdir.h
index afea0606..1d752090 100644
--- a/goo/gdir.h
+++ b/goo/gdir.h
@@ -16,7 +16,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2006 Kristian Høgsberg <k...@redhat.com>
-// Copyright (C) 2009, 2011, 2012, 2017, 2018, 2021 Albert Astals Cid 
<aa...@kde.org>
+// Copyright (C) 2009, 2011, 2012, 2017, 2018, 2021, 2022 Albert Astals Cid 
<aa...@kde.org>
 // Copyright (C) 2009 Kovid Goyal <ko...@kovidgoyal.net>
 // Copyright (C) 2013 Adam Reichold <adamreich...@myopera.com>
 // Copyright (C) 2013, 2017 Adrian Johnson <ajohn...@redneon.com>
@@ -37,6 +37,8 @@
 
 #include "poppler-config.h"
 
+#include <memory>
+
 class GooString;
 
 //------------------------------------------------------------------------
@@ -71,7 +73,7 @@ public:
     GDir(const GDir &other) = delete;
     GDir &operator=(const GDir &other) = delete;
 
-    GDirEntry *getNextEntry();
+    std::unique_ptr<GDirEntry> getNextEntry();
     void rewind();
 
 private:
diff --git a/goo/gfile.cc b/goo/gfile.cc
index d93cc244..f0e68eee 100644
--- a/goo/gfile.cc
+++ b/goo/gfile.cc
@@ -19,7 +19,7 @@
 // Copyright (C) 2006 Kristian Høgsberg <k...@redhat.com>
 // Copyright (C) 2008 Adam Batkin <a...@batkin.net>
 // Copyright (C) 2008, 2010, 2012, 2013 Hib Eris <h...@hiberis.nl>
-// Copyright (C) 2009, 2012, 2014, 2017, 2018, 2021 Albert Astals Cid 
<aa...@kde.org>
+// Copyright (C) 2009, 2012, 2014, 2017, 2018, 2021, 2022 Albert Astals Cid 
<aa...@kde.org>
 // Copyright (C) 2009 Kovid Goyal <ko...@kovidgoyal.net>
 // Copyright (C) 2013, 2018 Adam Reichold <adamreich...@myopera.com>
 // Copyright (C) 2013, 2017 Adrian Johnson <ajohn...@redneon.com>
@@ -492,17 +492,16 @@ GDir::~GDir()
 #endif
 }
 
-GDirEntry *GDir::getNextEntry()
+std::unique_ptr<GDirEntry> GDir::getNextEntry()
 {
-    GDirEntry *e = nullptr;
-
 #ifdef _WIN32
     if (hnd != INVALID_HANDLE_VALUE) {
-        e = new GDirEntry(path->c_str(), ffd.cFileName, doStat);
+        auto e = std::make_unique<GDirEntry>(path->c_str(), ffd.cFileName, 
doStat);
         if (!FindNextFileA(hnd, &ffd)) {
             FindClose(hnd);
             hnd = INVALID_HANDLE_VALUE;
         }
+        return e;
     }
 #else
     struct dirent *ent;
@@ -511,12 +510,12 @@ GDirEntry *GDir::getNextEntry()
             ent = readdir(dir);
         } while (ent && (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, 
"..")));
         if (ent) {
-            e = new GDirEntry(path->c_str(), ent->d_name, doStat);
+            return std::make_unique<GDirEntry>(path->c_str(), ent->d_name, 
doStat);
         }
     }
 #endif
 
-    return e;
+    return {};
 }
 
 void GDir::rewind()
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 70c05e76..e054bc43 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2005 Martin Kretzschmar <mart...@gnome.org>
 // Copyright (C) 2005, 2006 Kristian Høgsberg <k...@redhat.com>
-// Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2021 Albert Astals Cid 
<aa...@kde.org>
+// Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2022 Albert Astals Cid 
<aa...@kde.org>
 // Copyright (C) 2005 Jonathan Blandford <j...@redhat.com>
 // Copyright (C) 2006, 2007 Jeff Muizelaar <j...@infidigm.net>
 // Copyright (C) 2006 Takashi Iwai <ti...@suse.de>
@@ -456,7 +456,7 @@ GlobalParams::GlobalParams(const char 
*customPopplerDataDir) : popplerDataDir(cu
 void GlobalParams::scanEncodingDirs()
 {
     GDir *dir;
-    GDirEntry *entry;
+    std::unique_ptr<GDirEntry> entry;
     const char *dataRoot = popplerDataDir ? popplerDataDir : POPPLER_DATADIR;
 
     // allocate buffer large enough to append "/nameToUnicode"
@@ -469,7 +469,6 @@ void GlobalParams::scanEncodingDirs()
         if (!entry->isDir()) {
             parseNameToUnicode(entry->getFullPath());
         }
-        delete entry;
     }
     delete dir;
 
@@ -477,7 +476,6 @@ void GlobalParams::scanEncodingDirs()
     dir = new GDir(dataPathBuffer, false);
     while (entry = dir->getNextEntry(), entry != nullptr) {
         addCIDToUnicode(entry->getName(), entry->getFullPath());
-        delete entry;
     }
     delete dir;
 
@@ -485,7 +483,6 @@ void GlobalParams::scanEncodingDirs()
     dir = new GDir(dataPathBuffer, false);
     while (entry = dir->getNextEntry(), entry != nullptr) {
         addUnicodeMap(entry->getName(), entry->getFullPath());
-        delete entry;
     }
     delete dir;
 
@@ -494,7 +491,6 @@ void GlobalParams::scanEncodingDirs()
     while (entry = dir->getNextEntry(), entry != nullptr) {
         addCMapDir(entry->getName(), entry->getFullPath());
         toUnicodeDirs.push_back(entry->getFullPath()->copy());
-        delete entry;
     }
     delete dir;
 

Reply via email to