[poppler] fofi/FoFiTrueType.cc fofi/FoFiType1C.cc glib/poppler-document.cc goo/GooString.cc goo/GooString.h poppler/Annot.cc poppler/CurlCachedFile.cc poppler/Error.cc poppler/PSOutputDev.cc qt5/tests qt6/tests utils/HtmlOutputDev.cc utils/HtmlOutputDev.h utils/pdfsig.cc utils/pdftohtml.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 30 11:59:04 UTC 2022


 fofi/FoFiTrueType.cc            |   47 +++---------------
 fofi/FoFiType1C.cc              |  103 +++-------------------------------------
 glib/poppler-document.cc        |    6 +-
 goo/GooString.cc                |    8 +--
 goo/GooString.h                 |    5 +
 poppler/Annot.cc                |    6 --
 poppler/CurlCachedFile.cc       |    6 --
 poppler/Error.cc                |    4 -
 poppler/PSOutputDev.cc          |   48 +++++++-----------
 qt5/tests/check_annotations.cpp |    3 -
 qt5/tests/check_goostring.cpp   |   28 +++++-----
 qt6/tests/check_annotations.cpp |    3 -
 qt6/tests/check_goostring.cpp   |   28 +++++-----
 utils/HtmlOutputDev.cc          |   75 +++++++++++------------------
 utils/HtmlOutputDev.h           |    6 +-
 utils/pdfsig.cc                 |    6 --
 utils/pdftohtml.cc              |    5 -
 17 files changed, 118 insertions(+), 269 deletions(-)

New commits:
commit 022b361d431185f384456451c4bebe04a9fd1140
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Mar 30 13:48:43 2022 +0200

    Make GooString::format[v] return an unique_ptr

diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index ed37741b..020a374c 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -731,7 +731,6 @@ void FoFiTrueType::getFontMatrix(double *mat) const
 
 void FoFiTrueType::convertToType42(const char *psName, char **encoding, int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const
 {
-    GooString *buf;
     int maxUsedGlyph;
     bool ok;
 
@@ -741,9 +740,8 @@ void FoFiTrueType::convertToType42(const char *psName, char **encoding, int *cod
 
     // write the header
     ok = true;
-    buf = GooString::format("%!PS-TrueTypeFont-{0:2g}\n", (double)getS32BE(0, &ok) / 65536.0);
+    std::unique_ptr<GooString> buf = GooString::format("%!PS-TrueTypeFont-{0:2g}\n", (double)getS32BE(0, &ok) / 65536.0);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
 
     // begin the font dictionary
     (*outputFunc)(outputStream, "10 dict begin\n", 14);
@@ -754,7 +752,6 @@ void FoFiTrueType::convertToType42(const char *psName, char **encoding, int *cod
     (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
     buf = GooString::format("/FontBBox [{0:d} {1:d} {2:d} {3:d}] def\n", bbox[0], bbox[1], bbox[2], bbox[3]);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "/PaintType 0 def\n", 17);
 
     // write the guts of the dictionary
@@ -784,7 +781,6 @@ void FoFiTrueType::convertToType1(const char *psName, const char **newEncoding,
 
 void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int nCIDs, bool needVerticalMetrics, FoFiOutputFunc outputFunc, void *outputStream) const
 {
-    GooString *buf;
     int cid, maxUsedGlyph;
     bool ok;
     int i, j, k;
@@ -795,9 +791,8 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
 
     // write the header
     ok = true;
-    buf = GooString::format("%!PS-TrueTypeFont-{0:2g}\n", (double)getS32BE(0, &ok) / 65536.0);
+    std::unique_ptr<GooString> buf = GooString::format("%!PS-TrueTypeFont-{0:2g}\n", (double)getS32BE(0, &ok) / 65536.0);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
 
     // begin the font dictionary
     (*outputFunc)(outputStream, "20 dict begin\n", 14);
@@ -815,7 +810,6 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
     if (cidMap) {
         buf = GooString::format("/CIDCount {0:d} def\n", nCIDs);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         if (nCIDs > 32767) {
             (*outputFunc)(outputStream, "/CIDMap [", 9);
             for (i = 0; i < nCIDs; i += 32768 - 16) {
@@ -826,7 +820,6 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
                         cid = cidMap[i + j + k];
                         buf = GooString::format("{0:02x}{1:02x}", (cid >> 8) & 0xff, cid & 0xff);
                         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                        delete buf;
                     }
                     (*outputFunc)(outputStream, "\n", 1);
                 }
@@ -842,7 +835,6 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
                     cid = cidMap[i + j];
                     buf = GooString::format("{0:02x}{1:02x}", (cid >> 8) & 0xff, cid & 0xff);
                     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                    delete buf;
                 }
                 (*outputFunc)(outputStream, "\n", 1);
             }
@@ -852,32 +844,26 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
         // direct mapping - just fill the string(s) with s[i]=i
         buf = GooString::format("/CIDCount {0:d} def\n", nGlyphs);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         if (nGlyphs > 32767) {
             (*outputFunc)(outputStream, "/CIDMap [\n", 10);
             for (i = 0; i < nGlyphs; i += 32767) {
                 j = nGlyphs - i < 32767 ? nGlyphs - i : 32767;
                 buf = GooString::format("  {0:d} string 0 1 {1:d} {{\n", 2 * j, j - 1);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
                 buf = GooString::format("    2 copy dup 2 mul exch {0:d} add -8 bitshift put\n", i);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
                 buf = GooString::format("    1 index exch dup 2 mul 1 add exch {0:d} add"
                                         " 255 and put\n",
                                         i);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
                 (*outputFunc)(outputStream, "  } for\n", 8);
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         } else {
             buf = GooString::format("/CIDMap {0:d} string\n", 2 * nGlyphs);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
             buf = GooString::format("  0 1 {0:d} {{\n", nGlyphs - 1);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
             (*outputFunc)(outputStream, "    2 copy dup 2 mul exch -8 bitshift put\n", 42);
             (*outputFunc)(outputStream, "    1 index exch dup 2 mul 1 add exch 255 and put\n", 50);
             (*outputFunc)(outputStream, "  } for\n", 8);
@@ -887,7 +873,6 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
     (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
     buf = GooString::format("/FontBBox [{0:d} {1:d} {2:d} {3:d}] def\n", bbox[0], bbox[1], bbox[2], bbox[3]);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "/PaintType 0 def\n", 17);
     (*outputFunc)(outputStream, "/Encoding [] readonly def\n", 26);
     (*outputFunc)(outputStream, "/CharStrings 1 dict dup begin\n", 30);
@@ -919,7 +904,6 @@ void FoFiTrueType::convertToCIDType0(const char *psName, int *cidMap, int nCIDs,
 
 void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bool needVerticalMetrics, int *maxValidGlyph, FoFiOutputFunc outputFunc, void *outputStream) const
 {
-    GooString *buf;
     GooString *sfntsName;
     int maxUsedGlyph, n, i, j;
 
@@ -968,14 +952,12 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
         (*outputFunc)(outputStream, "10 dict begin\n", 14);
         (*outputFunc)(outputStream, "/FontName /", 11);
         (*outputFunc)(outputStream, psName, strlen(psName));
-        buf = GooString::format("_{0:02x} def\n", i >> 8);
+        std::unique_ptr<GooString> buf = GooString::format("_{0:02x} def\n", i >> 8);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         (*outputFunc)(outputStream, "/FontType 42 def\n", 17);
         (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
         buf = GooString::format("/FontBBox [{0:d} {1:d} {2:d} {3:d}] def\n", bbox[0], bbox[1], bbox[2], bbox[3]);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         (*outputFunc)(outputStream, "/PaintType 0 def\n", 17);
         (*outputFunc)(outputStream, "/sfnts ", 7);
         (*outputFunc)(outputStream, psName, strlen(psName));
@@ -984,7 +966,6 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
         for (j = 0; j < 256 && i + j < n; ++j) {
             buf = GooString::format("dup {0:d} /c{1:02x} put\n", j, j);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         (*outputFunc)(outputStream, "readonly def\n", 13);
         (*outputFunc)(outputStream, "/CharStrings 257 dict dup begin\n", 32);
@@ -992,7 +973,6 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
         for (j = 0; j < 256 && i + j < n; ++j) {
             buf = GooString::format("/c{0:02x} {1:d} def\n", j, cidMap ? cidMap[i + j] : i + j);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         (*outputFunc)(outputStream, "end readonly def\n", 17);
         (*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
@@ -1008,18 +988,16 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
     (*outputFunc)(outputStream, "/FMapType 2 def\n", 16);
     (*outputFunc)(outputStream, "/Encoding [\n", 12);
     for (i = 0; i < n; i += 256) {
-        buf = GooString::format("{0:d}\n", i >> 8);
+        const std::unique_ptr<GooString> buf = GooString::format("{0:d}\n", i >> 8);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
     (*outputFunc)(outputStream, "] def\n", 6);
     (*outputFunc)(outputStream, "/FDepVector [\n", 14);
     for (i = 0; i < n; i += 256) {
         (*outputFunc)(outputStream, "/", 1);
         (*outputFunc)(outputStream, psName, strlen(psName));
-        buf = GooString::format("_{0:02x} findfont\n", i >> 8);
+        const std::unique_ptr<GooString> buf = GooString::format("_{0:02x} findfont\n", i >> 8);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
     (*outputFunc)(outputStream, "] def\n", 6);
     (*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
@@ -1044,7 +1022,6 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, Fo
 void FoFiTrueType::cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void *outputStream) const
 {
     const char *name;
-    GooString *buf;
     int i;
 
     (*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
@@ -1053,17 +1030,15 @@ void FoFiTrueType::cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void
             if (!(name = encoding[i])) {
                 name = ".notdef";
             }
-            buf = GooString::format("dup {0:d} /", i);
+            const std::unique_ptr<GooString> buf = GooString::format("dup {0:d} /", i);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
             (*outputFunc)(outputStream, name, strlen(name));
             (*outputFunc)(outputStream, " put\n", 5);
         }
     } else {
         for (i = 0; i < 256; ++i) {
-            buf = GooString::format("dup {0:d} /c{1:02x} put\n", i, i);
+            const std::unique_ptr<GooString> buf = GooString::format("dup {0:d} /c{1:02x} put\n", i, i);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
     }
     (*outputFunc)(outputStream, "readonly def\n", 13);
@@ -1072,7 +1047,6 @@ void FoFiTrueType::cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void
 void FoFiTrueType::cvtCharStrings(char **encoding, const int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const
 {
     const char *name;
-    GooString *buf;
     char buf2[16];
     int i, k;
 
@@ -1108,9 +1082,8 @@ void FoFiTrueType::cvtCharStrings(char **encoding, const int *codeToGID, FoFiOut
             if (k > 0 && k < nGlyphs) {
                 (*outputFunc)(outputStream, "/", 1);
                 (*outputFunc)(outputStream, name, strlen(name));
-                buf = GooString::format(" {0:d} def\n", k);
+                const std::unique_ptr<GooString> buf = GooString::format(" {0:d} def\n", k);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
         }
     }
@@ -1446,15 +1419,13 @@ void FoFiTrueType::cvtSfnts(FoFiOutputFunc outputFunc, void *outputStream, const
 
 void FoFiTrueType::dumpString(const unsigned char *s, int length, FoFiOutputFunc outputFunc, void *outputStream) const
 {
-    GooString *buf;
     int pad, i, j;
 
     (*outputFunc)(outputStream, "<", 1);
     for (i = 0; i < length; i += 32) {
         for (j = 0; j < 32 && i + j < length; ++j) {
-            buf = GooString::format("{0:02x}", s[i + j] & 0xff);
+            const std::unique_ptr<GooString> buf = GooString::format("{0:02x}", s[i + j] & 0xff);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (i % (65536 - 32) == 65536 - 64) {
             (*outputFunc)(outputStream, ">\n<", 3);
diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 50a52247..a1511f1b 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -13,7 +13,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2009, 2010, 2017-2021 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2009, 2010, 2017-2022 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
 // Copyright (C) 2019 Tomoyuki Kubota <himajin100000 at gmail.com>
@@ -192,7 +192,6 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
     Type1CEexecBuf eb;
     Type1CIndex subrIdx;
     Type1CIndexVal val;
-    GooString *buf;
     char buf2[256];
     bool ok;
     int i;
@@ -258,37 +257,29 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
     } else {
         (*outputFunc)(outputStream, "/isFixedPitch false def\n", 24);
     }
-    buf = GooString::format("/ItalicAngle {0:.4g} def\n", topDict.italicAngle);
+    std::unique_ptr<GooString> buf = GooString::format("/ItalicAngle {0:.4g} def\n", topDict.italicAngle);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     buf = GooString::format("/UnderlinePosition {0:.4g} def\n", topDict.underlinePosition);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     buf = GooString::format("/UnderlineThickness {0:.4g} def\n", topDict.underlineThickness);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "end readonly def\n", 17);
     (*outputFunc)(outputStream, "/FontName /", 11);
     (*outputFunc)(outputStream, psName, psNameLen);
     (*outputFunc)(outputStream, " def\n", 5);
     buf = GooString::format("/PaintType {0:d} def\n", topDict.paintType);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "/FontType 1 def\n", 16);
     buf = GooString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] readonly def\n", topDict.fontMatrix[0], topDict.fontMatrix[1], topDict.fontMatrix[2], topDict.fontMatrix[3], topDict.fontMatrix[4],
                             topDict.fontMatrix[5]);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     buf = GooString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] readonly def\n", topDict.fontBBox[0], topDict.fontBBox[1], topDict.fontBBox[2], topDict.fontBBox[3]);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     buf = GooString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     if (topDict.uniqueID != 0) {
         buf = GooString::format("/UniqueID {0:d} def\n", topDict.uniqueID);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
 
     // write the encoding
@@ -303,7 +294,6 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
             if (enc && enc[i]) {
                 buf = GooString::format("dup {0:d} /{1:s} put\n", i, enc[i]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
         }
         (*outputFunc)(outputStream, "readonly def\n", 13);
@@ -333,7 +323,6 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
         for (i = 0; i < privateDicts[0].nBlueValues; ++i) {
             buf = GooString::format("{0:s}{1:d}", i > 0 ? " " : "", privateDicts[0].blueValues[i]);
             eexecWrite(&eb, buf->c_str());
-            delete buf;
         }
         eexecWrite(&eb, "] def\n");
     }
@@ -342,7 +331,6 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
         for (i = 0; i < privateDicts[0].nOtherBlues; ++i) {
             buf = GooString::format("{0:s}{1:d}", i > 0 ? " " : "", privateDicts[0].otherBlues[i]);
             eexecWrite(&eb, buf->c_str());
-            delete buf;
         }
         eexecWrite(&eb, "] def\n");
     }
@@ -351,7 +339,6 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
         for (i = 0; i < privateDicts[0].nFamilyBlues; ++i) {
             buf = GooString::format("{0:s}{1:d}", i > 0 ? " " : "", privateDicts[0].familyBlues[i]);
             eexecWrite(&eb, buf->c_str());
-            delete buf;
         }
         eexecWrite(&eb, "] def\n");
     }
@@ -360,41 +347,34 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
         for (i = 0; i < privateDicts[0].nFamilyOtherBlues; ++i) {
             buf = GooString::format("{0:s}{1:d}", i > 0 ? " " : "", privateDicts[0].familyOtherBlues[i]);
             eexecWrite(&eb, buf->c_str());
-            delete buf;
         }
         eexecWrite(&eb, "] def\n");
     }
     if (privateDicts[0].blueScale != 0.039625) {
         buf = GooString::format("/BlueScale {0:.4g} def\n", privateDicts[0].blueScale);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].blueShift != 7) {
         buf = GooString::format("/BlueShift {0:d} def\n", privateDicts[0].blueShift);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].blueFuzz != 1) {
         buf = GooString::format("/BlueFuzz {0:d} def\n", privateDicts[0].blueFuzz);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].hasStdHW) {
         buf = GooString::format("/StdHW [{0:.4g}] def\n", privateDicts[0].stdHW);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].hasStdVW) {
         buf = GooString::format("/StdVW [{0:.4g}] def\n", privateDicts[0].stdVW);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].nStemSnapH) {
         eexecWrite(&eb, "/StemSnapH [");
         for (i = 0; i < privateDicts[0].nStemSnapH; ++i) {
             buf = GooString::format("{0:s}{1:.4g}", i > 0 ? " " : "", privateDicts[0].stemSnapH[i]);
             eexecWrite(&eb, buf->c_str());
-            delete buf;
         }
         eexecWrite(&eb, "] def\n");
     }
@@ -403,29 +383,24 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
         for (i = 0; i < privateDicts[0].nStemSnapV; ++i) {
             buf = GooString::format("{0:s}{1:.4g}", i > 0 ? " " : "", privateDicts[0].stemSnapV[i]);
             eexecWrite(&eb, buf->c_str());
-            delete buf;
         }
         eexecWrite(&eb, "] def\n");
     }
     if (privateDicts[0].hasForceBold) {
         buf = GooString::format("/ForceBold {0:s} def\n", privateDicts[0].forceBold ? "true" : "false");
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].forceBoldThreshold != 0) {
         buf = GooString::format("/ForceBoldThreshold {0:.4g} def\n", privateDicts[0].forceBoldThreshold);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].languageGroup != 0) {
         buf = GooString::format("/LanguageGroup {0:d} def\n", privateDicts[0].languageGroup);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
     if (privateDicts[0].expansionFactor != 0.06) {
         buf = GooString::format("/ExpansionFactor {0:.4g} def\n", privateDicts[0].expansionFactor);
         eexecWrite(&eb, buf->c_str());
-        delete buf;
     }
 
     // set up subroutines
@@ -438,7 +413,6 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
     // write the CharStrings
     buf = GooString::format("2 index /CharStrings {0:d} dict dup begin\n", nGlyphs);
     eexecWrite(&eb, buf->c_str());
-    delete buf;
     for (i = 0; i < nGlyphs; ++i) {
         ok = true;
         getIndexVal(&charStringsIdx, i, &val, &ok);
@@ -474,7 +448,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
     Type1CIndex subrIdx;
     Type1CIndexVal val;
     int nCIDs, gdBytes;
-    GooString *buf;
     char buf2[256];
     bool ok;
     int gid, offset, n, i, j, k;
@@ -574,15 +547,13 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
         (*outputFunc)(outputStream, "  /Registry (Adobe) def\n", 24);
         (*outputFunc)(outputStream, "  /Ordering (Identity) def\n", 27);
     }
-    buf = GooString::format("  /Supplement {0:d} def\n", topDict.supplement);
+    std::unique_ptr<GooString> buf = GooString::format("  /Supplement {0:d} def\n", topDict.supplement);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "end def\n", 8);
     if (topDict.hasFontMatrix) {
         buf = GooString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n", topDict.fontMatrix[0], topDict.fontMatrix[1], topDict.fontMatrix[2], topDict.fontMatrix[3], topDict.fontMatrix[4],
                                 topDict.fontMatrix[5]);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     } else if (privateDicts[0].hasFontMatrix) {
         (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
     } else {
@@ -590,7 +561,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
     }
     buf = GooString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] def\n", topDict.fontBBox[0], topDict.fontBBox[1], topDict.fontBBox[2], topDict.fontBBox[3]);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "/FontInfo 1 dict dup begin\n", 27);
     (*outputFunc)(outputStream, "  /FSType 8 def\n", 16);
     (*outputFunc)(outputStream, "end def\n", 8);
@@ -598,48 +568,39 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
     // CIDFont-specific entries
     buf = GooString::format("/CIDCount {0:d} def\n", nCIDs);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "/FDBytes 1 def\n", 15);
     buf = GooString::format("/GDBytes {0:d} def\n", gdBytes);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     (*outputFunc)(outputStream, "/CIDMapOffset 0 def\n", 20);
     if (topDict.paintType != 0) {
         buf = GooString::format("/PaintType {0:d} def\n", topDict.paintType);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         buf = GooString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
 
     // FDArray entry
     buf = GooString::format("/FDArray {0:d} array\n", nFDs);
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
     for (i = 0; i < nFDs; ++i) {
         buf = GooString::format("dup {0:d} 10 dict begin\n", i);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         (*outputFunc)(outputStream, "/FontType 1 def\n", 16);
         if (privateDicts[i].hasFontMatrix) {
             buf = GooString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n", privateDicts[i].fontMatrix[0], privateDicts[i].fontMatrix[1], privateDicts[i].fontMatrix[2], privateDicts[i].fontMatrix[3],
                                     privateDicts[i].fontMatrix[4], privateDicts[i].fontMatrix[5]);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         } else {
             (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
         }
         buf = GooString::format("/PaintType {0:d} def\n", topDict.paintType);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
         (*outputFunc)(outputStream, "/Private 32 dict begin\n", 23);
         if (privateDicts[i].nBlueValues) {
             (*outputFunc)(outputStream, "/BlueValues [", 13);
             for (j = 0; j < privateDicts[i].nBlueValues; ++j) {
                 buf = GooString::format("{0:s}{1:d}", j > 0 ? " " : "", privateDicts[i].blueValues[j]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         }
@@ -648,7 +609,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
             for (j = 0; j < privateDicts[i].nOtherBlues; ++j) {
                 buf = GooString::format("{0:s}{1:d}", j > 0 ? " " : "", privateDicts[i].otherBlues[j]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         }
@@ -657,7 +617,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
             for (j = 0; j < privateDicts[i].nFamilyBlues; ++j) {
                 buf = GooString::format("{0:s}{1:d}", j > 0 ? " " : "", privateDicts[i].familyBlues[j]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         }
@@ -666,41 +625,34 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
             for (j = 0; j < privateDicts[i].nFamilyOtherBlues; ++j) {
                 buf = GooString::format("{0:s}{1:d}", j > 0 ? " " : "", privateDicts[i].familyOtherBlues[j]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         }
         if (privateDicts[i].blueScale != 0.039625) {
             buf = GooString::format("/BlueScale {0:.4g} def\n", privateDicts[i].blueScale);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].blueShift != 7) {
             buf = GooString::format("/BlueShift {0:d} def\n", privateDicts[i].blueShift);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].blueFuzz != 1) {
             buf = GooString::format("/BlueFuzz {0:d} def\n", privateDicts[i].blueFuzz);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].hasStdHW) {
             buf = GooString::format("/StdHW [{0:.4g}] def\n", privateDicts[i].stdHW);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].hasStdVW) {
             buf = GooString::format("/StdVW [{0:.4g}] def\n", privateDicts[i].stdVW);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].nStemSnapH) {
             (*outputFunc)(outputStream, "/StemSnapH [", 12);
             for (j = 0; j < privateDicts[i].nStemSnapH; ++j) {
                 buf = GooString::format("{0:s}{1:.4g}", j > 0 ? " " : "", privateDicts[i].stemSnapH[j]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         }
@@ -709,29 +661,24 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
             for (j = 0; j < privateDicts[i].nStemSnapV; ++j) {
                 buf = GooString::format("{0:s}{1:.4g}", j > 0 ? " " : "", privateDicts[i].stemSnapV[j]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "] def\n", 6);
         }
         if (privateDicts[i].hasForceBold) {
             buf = GooString::format("/ForceBold {0:s} def\n", privateDicts[i].forceBold ? "true" : "false");
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].forceBoldThreshold != 0) {
             buf = GooString::format("/ForceBoldThreshold {0:.4g} def\n", privateDicts[i].forceBoldThreshold);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].languageGroup != 0) {
             buf = GooString::format("/LanguageGroup {0:d} def\n", privateDicts[i].languageGroup);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (privateDicts[i].expansionFactor != 0.06) {
             buf = GooString::format("/ExpansionFactor {0:.4g} def\n", privateDicts[i].expansionFactor);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         (*outputFunc)(outputStream, "currentdict end def\n", 20);
         (*outputFunc)(outputStream, "currentdict end put\n", 20);
@@ -742,7 +689,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
     offset = (nCIDs + 1) * (1 + gdBytes);
     buf = GooString::format("(Hex) {0:d} StartData\n", offset + charStrings->getLength());
     (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-    delete buf;
 
     // write the charstring offset (CIDMap) table
     for (i = 0; i <= nCIDs; i += 6) {
@@ -760,7 +706,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
             for (k = 0; k <= gdBytes; ++k) {
                 buf = GooString::format("{0:02x}", buf2[k] & 0xff);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
         }
         (*outputFunc)(outputStream, "\n", 1);
@@ -772,7 +717,6 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
         for (j = 0; j < 32 && i + j < n; ++j) {
             buf = GooString::format("{0:02x}", charStrings->getChar(i + j) & 0xff);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
         }
         if (i + 32 >= n) {
             (*outputFunc)(outputStream, ">", 1);
@@ -791,7 +735,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
     Type1CIndex subrIdx;
     Type1CIndexVal val;
     int nCIDs;
-    GooString *buf;
     Type1CEexecBuf eb;
     bool ok;
     int fd, i, j, k;
@@ -855,15 +798,13 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
             (*outputFunc)(outputStream, "16 dict begin\n", 14);
             (*outputFunc)(outputStream, "/FontName /", 11);
             (*outputFunc)(outputStream, psName, strlen(psName));
-            buf = GooString::format("_{0:02x} def\n", i >> 8);
+            std::unique_ptr<GooString> buf = GooString::format("_{0:02x} def\n", i >> 8);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
             (*outputFunc)(outputStream, "/FontType 1 def\n", 16);
             if (privateDicts[fd].hasFontMatrix) {
                 buf = GooString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n", privateDicts[fd].fontMatrix[0], privateDicts[fd].fontMatrix[1], privateDicts[fd].fontMatrix[2], privateDicts[fd].fontMatrix[3],
                                         privateDicts[fd].fontMatrix[4], privateDicts[fd].fontMatrix[5]);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             } else if (topDict.hasFontMatrix) {
                 (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
             } else {
@@ -871,25 +812,20 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
             }
             buf = GooString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] def\n", topDict.fontBBox[0], topDict.fontBBox[1], topDict.fontBBox[2], topDict.fontBBox[3]);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
             buf = GooString::format("/PaintType {0:d} def\n", topDict.paintType);
             (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-            delete buf;
             if (topDict.paintType != 0) {
                 buf = GooString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
             for (j = 0; j < 256 && i + j < nCIDs; ++j) {
                 buf = GooString::format("dup {0:d} /c{1:02x} put\n", j, j);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             if (j < 256) {
                 buf = GooString::format("{0:d} 1 255 {{ 1 index exch /.notdef put }} for\n", j);
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
             }
             (*outputFunc)(outputStream, "readonly def\n", 13);
             (*outputFunc)(outputStream, "currentdict end\n", 16);
@@ -917,7 +853,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
                 for (k = 0; k < privateDicts[fd].nBlueValues; ++k) {
                     buf = GooString::format("{0:s}{1:d}", k > 0 ? " " : "", privateDicts[fd].blueValues[k]);
                     eexecWrite(&eb, buf->c_str());
-                    delete buf;
                 }
                 eexecWrite(&eb, "] def\n");
             }
@@ -926,7 +861,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
                 for (k = 0; k < privateDicts[fd].nOtherBlues; ++k) {
                     buf = GooString::format("{0:s}{1:d}", k > 0 ? " " : "", privateDicts[fd].otherBlues[k]);
                     eexecWrite(&eb, buf->c_str());
-                    delete buf;
                 }
                 eexecWrite(&eb, "] def\n");
             }
@@ -935,7 +869,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
                 for (k = 0; k < privateDicts[fd].nFamilyBlues; ++k) {
                     buf = GooString::format("{0:s}{1:d}", k > 0 ? " " : "", privateDicts[fd].familyBlues[k]);
                     eexecWrite(&eb, buf->c_str());
-                    delete buf;
                 }
                 eexecWrite(&eb, "] def\n");
             }
@@ -944,41 +877,34 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
                 for (k = 0; k < privateDicts[fd].nFamilyOtherBlues; ++k) {
                     buf = GooString::format("{0:s}{1:d}", k > 0 ? " " : "", privateDicts[fd].familyOtherBlues[k]);
                     eexecWrite(&eb, buf->c_str());
-                    delete buf;
                 }
                 eexecWrite(&eb, "] def\n");
             }
             if (privateDicts[fd].blueScale != 0.039625) {
                 buf = GooString::format("/BlueScale {0:.4g} def\n", privateDicts[fd].blueScale);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].blueShift != 7) {
                 buf = GooString::format("/BlueShift {0:d} def\n", privateDicts[fd].blueShift);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].blueFuzz != 1) {
                 buf = GooString::format("/BlueFuzz {0:d} def\n", privateDicts[fd].blueFuzz);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].hasStdHW) {
                 buf = GooString::format("/StdHW [{0:.4g}] def\n", privateDicts[fd].stdHW);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].hasStdVW) {
                 buf = GooString::format("/StdVW [{0:.4g}] def\n", privateDicts[fd].stdVW);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].nStemSnapH) {
                 eexecWrite(&eb, "/StemSnapH [");
                 for (k = 0; k < privateDicts[fd].nStemSnapH; ++k) {
                     buf = GooString::format("{0:s}{1:.4g}", k > 0 ? " " : "", privateDicts[fd].stemSnapH[k]);
                     eexecWrite(&eb, buf->c_str());
-                    delete buf;
                 }
                 eexecWrite(&eb, "] def\n");
             }
@@ -987,29 +913,24 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
                 for (k = 0; k < privateDicts[fd].nStemSnapV; ++k) {
                     buf = GooString::format("{0:s}{1:.4g}", k > 0 ? " " : "", privateDicts[fd].stemSnapV[k]);
                     eexecWrite(&eb, buf->c_str());
-                    delete buf;
                 }
                 eexecWrite(&eb, "] def\n");
             }
             if (privateDicts[fd].hasForceBold) {
                 buf = GooString::format("/ForceBold {0:s} def\n", privateDicts[fd].forceBold ? "true" : "false");
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].forceBoldThreshold != 0) {
                 buf = GooString::format("/ForceBoldThreshold {0:.4g} def\n", privateDicts[fd].forceBoldThreshold);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].languageGroup != 0) {
                 buf = GooString::format("/LanguageGroup {0:d} def\n", privateDicts[fd].languageGroup);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
             if (privateDicts[fd].expansionFactor != 0.06) {
                 buf = GooString::format("/ExpansionFactor {0:.4g} def\n", privateDicts[fd].expansionFactor);
                 eexecWrite(&eb, buf->c_str());
-                delete buf;
             }
 
             // set up the subroutines
@@ -1037,7 +958,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
                     if (ok) {
                         buf = GooString::format("c{0:02x}", j);
                         eexecCvtGlyph(&eb, buf->c_str(), val.pos, val.len, &subrIdx, &privateDicts[fd]);
-                        delete buf;
                     }
                 }
             }
@@ -1068,28 +988,25 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
     (*outputFunc)(outputStream, " def\n", 5);
     (*outputFunc)(outputStream, "/FontType 0 def\n", 16);
     if (topDict.hasFontMatrix) {
-        buf = GooString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n", topDict.fontMatrix[0], topDict.fontMatrix[1], topDict.fontMatrix[2], topDict.fontMatrix[3], topDict.fontMatrix[4],
-                                topDict.fontMatrix[5]);
+        const std::unique_ptr<GooString> buf = GooString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n", topDict.fontMatrix[0], topDict.fontMatrix[1], topDict.fontMatrix[2], topDict.fontMatrix[3],
+                                                                 topDict.fontMatrix[4], topDict.fontMatrix[5]);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     } else {
         (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
     }
     (*outputFunc)(outputStream, "/FMapType 2 def\n", 16);
     (*outputFunc)(outputStream, "/Encoding [\n", 12);
     for (i = 0; i < nCIDs; i += 256) {
-        buf = GooString::format("{0:d}\n", i >> 8);
+        const std::unique_ptr<GooString> buf = GooString::format("{0:d}\n", i >> 8);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
     (*outputFunc)(outputStream, "] def\n", 6);
     (*outputFunc)(outputStream, "/FDepVector [\n", 14);
     for (i = 0; i < nCIDs; i += 256) {
         (*outputFunc)(outputStream, "/", 1);
         (*outputFunc)(outputStream, psName, strlen(psName));
-        buf = GooString::format("_{0:02x} findfont\n", i >> 8);
+        const std::unique_ptr<GooString> buf = GooString::format("_{0:02x} findfont\n", i >> 8);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
     (*outputFunc)(outputStream, "] def\n", 6);
     (*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
@@ -1099,7 +1016,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
 
 void FoFiType1C::eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName, int offset, int nBytes, const Type1CIndex *subrIdx, const Type1CPrivateDict *pDict)
 {
-    GooString *buf;
     GooString *charBuf;
 
     // generate the charstring
@@ -1107,9 +1023,8 @@ void FoFiType1C::eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName, int of
     std::set<int> offsetBeingParsed;
     cvtGlyph(offset, nBytes, charBuf, subrIdx, pDict, true, offsetBeingParsed);
 
-    buf = GooString::format("/{0:s} {1:d} RD ", glyphName, charBuf->getLength());
+    const std::unique_ptr<GooString> buf = GooString::format("/{0:s} {1:d} RD ", glyphName, charBuf->getLength());
     eexecWrite(eb, buf->c_str());
-    delete buf;
     eexecWriteCharstring(eb, (unsigned char *)charBuf->c_str(), charBuf->getLength());
     eexecWrite(eb, " ND\n");
 
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index a74312ff..5de08108 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -5,7 +5,7 @@
  * Copyright (C) 2018, 2019, 2021, 2022 Marek Kasik <mkasik at redhat.com>
  * Copyright (C) 2019 Masamichi Hosoda <trueroad at trueroad.jp>
  * Copyright (C) 2019, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
- * Copyright (C) 2020 Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2020, 2022 Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2021 André Guerreiro <aguerreiro1985 at gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -3799,7 +3799,7 @@ GooString *_poppler_convert_date_time_to_pdf_date(GDateTime *datetime)
 {
     int offset_min;
     gchar *date_str;
-    GooString *out_str;
+    std::unique_ptr<GooString> out_str;
 
     offset_min = g_date_time_get_utc_offset(datetime) / 1000000 / 60;
     date_str = g_date_time_format(datetime, "D:%Y%m%d%H%M%S");
@@ -3813,5 +3813,5 @@ GooString *_poppler_convert_date_time_to_pdf_date(GDateTime *datetime)
     }
 
     g_free(date_str);
-    return out_str;
+    return out_str.release();
 }
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 470b79f5..f2fb3031 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -121,9 +121,9 @@ void formatDoubleSmallAware(double x, char *buf, int bufSize, int prec, bool tri
 
 //------------------------------------------------------------------------
 
-GooString *GooString::format(const char *fmt, ...)
+std::unique_ptr<GooString> GooString::format(const char *fmt, ...)
 {
-    auto *s = new GooString();
+    auto s = std::make_unique<GooString>();
 
     va_list argList;
     va_start(argList, fmt);
@@ -133,9 +133,9 @@ GooString *GooString::format(const char *fmt, ...)
     return s;
 }
 
-GooString *GooString::formatv(const char *fmt, va_list argList)
+std::unique_ptr<GooString> GooString::formatv(const char *fmt, va_list argList)
 {
-    auto *s = new GooString();
+    auto s = std::make_unique<GooString>();
 
     s->appendfv(fmt, argList);
 
diff --git a/goo/GooString.h b/goo/GooString.h
index 6613e10f..2b93915f 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -42,6 +42,7 @@
 #include "poppler_private_export.h"
 
 #include <cstdarg>
+#include <memory>
 #include <string>
 
 #ifdef __clang__
@@ -139,8 +140,8 @@ public:
     //     t -- GooString *
     //     w -- blank space; arg determines width
     // To get literal curly braces, use {{ or }}.
-    POPPLER_PRIVATE_EXPORT static GooString *format(const char *fmt, ...) GOOSTRING_FORMAT;
-    POPPLER_PRIVATE_EXPORT static GooString *formatv(const char *fmt, va_list argList);
+    POPPLER_PRIVATE_EXPORT static std::unique_ptr<GooString> format(const char *fmt, ...) GOOSTRING_FORMAT;
+    POPPLER_PRIVATE_EXPORT static std::unique_ptr<GooString> formatv(const char *fmt, va_list argList);
 
     // Get length.
     int getLength() const { return size(); }
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5b7a4173..60c023d4 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -5051,9 +5051,8 @@ bool AnnotAppearanceBuilder::drawSignatureFieldText(const FormFieldSignature *fi
         Matrix matrix = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
         matrix.scale(width, height);
         static const char *IMG_TMPL = "\nq {0:.1g} {1:.1g} {2:.1g} {3:.1g} {4:.1g} {5:.1g} cm /{6:s} Do Q\n";
-        const GooString *imgBuffer = GooString::format(IMG_TMPL, matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3], matrix.m[4], matrix.m[5], imageResourceId);
+        const std::unique_ptr<GooString> imgBuffer = GooString::format(IMG_TMPL, matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3], matrix.m[4], matrix.m[5], imageResourceId);
         append(imgBuffer->c_str());
-        delete imgBuffer;
     }
 
     const GooString &leftText = field->getCustomAppearanceLeftContent();
@@ -5639,11 +5638,10 @@ void AnnotStamp::generateStampDefaultAppearance()
     }
 
     const double bboxArray[4] = { 0, 0, rect->x2 - rect->x1, rect->y2 - rect->y1 };
-    const GooString *scale = GooString::format("{0:.6g} 0 0 {1:.6g} 0 0 cm\nq\n", bboxArray[2] / stampUnscaledWidth, bboxArray[3] / stampUnscaledHeight);
+    const std::unique_ptr<GooString> scale = GooString::format("{0:.6g} 0 0 {1:.6g} 0 0 cm\nq\n", bboxArray[2] / stampUnscaledWidth, bboxArray[3] / stampUnscaledHeight);
     defaultAppearanceBuilder.append(scale->c_str());
     defaultAppearanceBuilder.append(stampCode);
     defaultAppearanceBuilder.append("Q\n");
-    delete scale;
 
     Dict *resDict = new Dict(doc->getXRef());
     resDict->add("ExtGState", Object(extGStateDict));
diff --git a/poppler/CurlCachedFile.cc b/poppler/CurlCachedFile.cc
index aa7a33c0..1ff17220 100644
--- a/poppler/CurlCachedFile.cc
+++ b/poppler/CurlCachedFile.cc
@@ -6,7 +6,7 @@
 //
 // Copyright 2009 Stefan Thomas <thomas at eload24.com>
 // Copyright 2010, 2011 Hib Eris <hib at hiberis.nl>
-// Copyright 2010, 2019, 2021 Albert Astals Cid <aacid at kde.org>
+// Copyright 2010, 2019, 2021, 2022 Albert Astals Cid <aacid at kde.org>
 //
 //========================================================================
 
@@ -77,7 +77,7 @@ int CurlCachedFileLoader::load(const std::vector<ByteRange> &ranges, CachedFileW
 
         fromByte = bRange.offset;
         toByte = fromByte + bRange.length - 1;
-        GooString *range = GooString::format("{0:ulld}-{1:ulld}", fromByte, toByte);
+        const std::unique_ptr<GooString> range = GooString::format("{0:ulld}-{1:ulld}", fromByte, toByte);
 
         curl_easy_setopt(curl, CURLOPT_URL, url->c_str());
         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, load_cb);
@@ -86,8 +86,6 @@ int CurlCachedFileLoader::load(const std::vector<ByteRange> &ranges, CachedFileW
         r = curl_easy_perform(curl);
         curl_easy_reset(curl);
 
-        delete range;
-
         if (r != CURLE_OK) {
             break;
         }
diff --git a/poppler/Error.cc b/poppler/Error.cc
index 7edfe240..f821bba9 100644
--- a/poppler/Error.cc
+++ b/poppler/Error.cc
@@ -47,14 +47,13 @@ void setErrorCallback(ErrorCallback cbk)
 void CDECL error(ErrorCategory category, Goffset pos, const char *msg, ...)
 {
     va_list args;
-    GooString *s;
 
     // NB: this can be called before the globalParams object is created
     if (!errorCbk && globalParams && globalParams->getErrQuiet()) {
         return;
     }
     va_start(args, msg);
-    s = GooString::formatv(msg, args);
+    const std::unique_ptr<GooString> s = GooString::formatv(msg, args);
     va_end(args);
 
     GooString sanitized;
@@ -77,5 +76,4 @@ void CDECL error(ErrorCategory category, Goffset pos, const char *msg, ...)
         }
         fflush(stderr);
     }
-    delete s;
 }
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 47bd0827..effba6b1 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -976,16 +976,11 @@ struct PSOutImgClipRect
 
 struct PSOutPaperSize
 {
-    PSOutPaperSize(GooString *nameA, int wA, int hA)
-    {
-        name = nameA;
-        w = wA;
-        h = hA;
-    }
-    ~PSOutPaperSize() { delete name; }
+    PSOutPaperSize(std::unique_ptr<GooString> &&nameA, int wA, int hA) : name(std::move(nameA)), w(wA), h(hA) { }
+    ~PSOutPaperSize() = default;
     PSOutPaperSize(const PSOutPaperSize &) = delete;
     PSOutPaperSize &operator=(const PSOutPaperSize &) = delete;
-    GooString *name;
+    std::unique_ptr<GooString> name;
     int w, h;
 };
 
@@ -1379,10 +1374,10 @@ void PSOutputDev::postInit()
         }
         if (i == (int)paperSizes->size()) {
             const StandardMedia *media = standardMedia;
-            GooString *name = nullptr;
+            std::unique_ptr<GooString> name;
             while (media->name) {
                 if (pageDimensionEqual(w, media->width) && pageDimensionEqual(h, media->height)) {
-                    name = new GooString(media->name);
+                    name = std::make_unique<GooString>(media->name);
                     w = media->width;
                     h = media->height;
                     break;
@@ -1392,7 +1387,7 @@ void PSOutputDev::postInit()
             if (!name) {
                 name = GooString::format("{0:d}x{1:d}mm", int(w * 25.4 / 72), int(h * 25.4 / 72));
             }
-            paperSizes->push_back(new PSOutPaperSize(name, w, h));
+            paperSizes->push_back(new PSOutPaperSize(std::move(name), w, h));
         }
         pagePaperSize.insert(std::pair<int, int>(pg, i));
         if (!paperMatch) {
@@ -1638,7 +1633,7 @@ void PSOutputDev::writeHeader(int nPages, const PDFRectangle *mediaBox, const PD
     case psModePS:
         for (std::size_t i = 0; i < paperSizes->size(); ++i) {
             size = (*paperSizes)[i];
-            writePSFmt("%%{0:s} {1:t} {2:d} {3:d} 0 () ()\n", i == 0 ? "DocumentMedia:" : "+", size->name, size->w, size->h);
+            writePSFmt("%%{0:s} {1:t} {2:d} {3:d} 0 () ()\n", i == 0 ? "DocumentMedia:" : "+", size->name.get(), size->w, size->h);
         }
         writePSFmt("%%BoundingBox: 0 0 {0:d} {1:d}\n", paperWidth, paperHeight);
         writePSFmt("%%Pages: {0:d}\n", nPages);
@@ -1646,7 +1641,7 @@ void PSOutputDev::writeHeader(int nPages, const PDFRectangle *mediaBox, const PD
         if (!paperMatch) {
             size = (*paperSizes)[0];
             writePS("%%BeginDefaults\n");
-            writePSFmt("%%PageMedia: {0:t}\n", size->name);
+            writePSFmt("%%PageMedia: {0:t}\n", size->name.get());
             writePS("%%EndDefaults\n");
         }
         break;
@@ -1981,7 +1976,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict)
     subst = false;
 
     if (font->getType() == fontType3) {
-        psName = GooString::format("T3_{0:d}_{1:d}", font->getID()->num, font->getID()->gen);
+        psName = GooString::format("T3_{0:d}_{1:d}", font->getID()->num, font->getID()->gen).release();
         setupType3Font(font, psName, parentResDict);
     } else {
         std::optional<GfxFontLoc> fontLoc = font->locateFont(xref, this);
@@ -2699,7 +2694,6 @@ void PSOutputDev::setupType3Font(GfxFont *font, GooString *psName, Dict *parentR
     Gfx *gfx;
     PDFRectangle box;
     const double *m;
-    GooString *buf;
     int i;
 
     // set up resources used by font
@@ -2754,13 +2748,13 @@ void PSOutputDev::setupType3Font(GfxFont *font, GooString *psName, Dict *parentR
             Object charProc = charProcs->getVal(i);
             gfx->display(&charProc);
             if (t3String) {
+                std::unique_ptr<GooString> buf;
                 if (t3Cacheable) {
                     buf = GooString::format("{0:.6g} {1:.6g} {2:.6g} {3:.6g} {4:.6g} {5:.6g} setcachedevice\n", t3WX, t3WY, t3LLX, t3LLY, t3URX, t3URY);
                 } else {
                     buf = GooString::format("{0:.6g} {1:.6g} setcharwidth\n", t3WX, t3WY);
                 }
                 (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-                delete buf;
                 (*outputFunc)(outputStream, t3String->c_str(), t3String->getLength());
                 delete t3String;
                 t3String = nullptr;
@@ -2802,7 +2796,7 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id)
         }
         delete psName;
     }
-    psName = GooString::format("FF{0:d}_{1:d}", id->num, id->gen);
+    psName = GooString::format("FF{0:d}_{1:d}", id->num, id->gen).release();
     if ((s = font->getEmbeddedFontName())) {
         s = filterPSName(s->toStr());
         psName->append('_')->append(s);
@@ -3785,7 +3779,7 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA)
 
         if (paperMatch) {
             paperSize = (*paperSizes)[pagePaperSize[pageNum]];
-            writePSFmt("%%PageMedia: {0:t}\n", paperSize->name);
+            writePSFmt("%%PageMedia: {0:t}\n", paperSize->name.get());
         }
 
         // Create a matrix with the same transform that will be output to PS
@@ -6659,7 +6653,7 @@ void PSOutputDev::dumpColorSpaceL2(GfxState *state, GfxColorSpace *colorSpace, b
         Ref ref = iccBasedCS->getRef();
         const bool validref = ref != Ref::INVALID();
         int intent = state->getCmsRenderingIntent();
-        GooString *name;
+        std::unique_ptr<GooString> name;
         if (validref) {
             name = GooString::format("ICCBased-{0:d}-{1:d}-{2:d}", ref.num, ref.gen, intent);
         } else {
@@ -6668,16 +6662,16 @@ void PSOutputDev::dumpColorSpaceL2(GfxState *state, GfxColorSpace *colorSpace, b
         }
         const auto &it = iccEmitted.find(name->toStr());
         if (it != iccEmitted.end()) {
-            writePSFmt("{0:t}", name);
+            writePSFmt("{0:t}", name.get());
             if (genXform) {
                 writePS(" {}");
             }
         } else {
             char *csa = iccBasedCS->getPostScriptCSA();
             if (csa) {
-                writePSFmt("userdict /{0:t} {1:s} put\n", name, csa);
+                writePSFmt("userdict /{0:t} {1:s} put\n", name.get(), csa);
                 iccEmitted.emplace(name->toStr());
-                writePSFmt("{0:t}", name);
+                writePSFmt("{0:t}", name.get());
                 if (genXform) {
                     writePS(" {}");
                 }
@@ -6685,7 +6679,6 @@ void PSOutputDev::dumpColorSpaceL2(GfxState *state, GfxColorSpace *colorSpace, b
                 dumpColorSpaceL2(state, ((GfxICCBasedColorSpace *)colorSpace)->getAlt(), genXform, updateColors, false);
             }
         }
-        delete name;
     }
 #else
         // there is no transform function to the alternate color space, so
@@ -7375,15 +7368,13 @@ void PSOutputDev::writePSBuf(const char *s, int len)
 void PSOutputDev::writePSFmt(const char *fmt, ...)
 {
     va_list args;
-    GooString *buf;
 
     va_start(args, fmt);
     if (t3String) {
         t3String->appendfv((char *)fmt, args);
     } else {
-        buf = GooString::formatv((char *)fmt, args);
+        const std::unique_ptr<GooString> buf = GooString::formatv((char *)fmt, args);
         (*outputFunc)(outputStream, buf->c_str(), buf->getLength());
-        delete buf;
     }
     va_end(args);
 }
@@ -7510,10 +7501,9 @@ GooString *PSOutputDev::filterPSLabel(GooString *label, bool *needParens)
         } else if (c == '(') {
             label2->append("\\(");
         } else if (c < 0x20 || c > 0x7e) {
-            GooString *aux = GooString::format("\\{0:03o}", c);
-            label2->append(aux);
+            std::unique_ptr<GooString> aux = GooString::format("\\{0:03o}", c);
+            label2->append(aux.get());
             j += 4;
-            delete aux;
         } else {
             label2->append(c);
             ++j;
diff --git a/qt5/tests/check_annotations.cpp b/qt5/tests/check_annotations.cpp
index ed3501f2..0e8e88e4 100644
--- a/qt5/tests/check_annotations.cpp
+++ b/qt5/tests/check_annotations.cpp
@@ -35,9 +35,8 @@ void TestAnnotations::checkQColorPrecision()
     bool precisionOk = true;
     for (int i = std::numeric_limits<uint16_t>::min(); i <= std::numeric_limits<uint16_t>::max(); i++) {
         double normalized = static_cast<uint16_t>(i) / static_cast<double>(std::numeric_limits<uint16_t>::max());
-        GooString *serialized = GooString::format("{0:.5f}", normalized);
+        const std::unique_ptr<GooString> serialized = GooString::format("{0:.5f}", normalized);
         double deserialized = gatof(serialized->c_str());
-        delete serialized;
         uint16_t denormalized = std::round(deserialized * std::numeric_limits<uint16_t>::max());
         if (static_cast<uint16_t>(i) != denormalized) {
             precisionOk = false;
diff --git a/qt5/tests/check_goostring.cpp b/qt5/tests/check_goostring.cpp
index 4a07cc6d..cfb14c2a 100644
--- a/qt5/tests/check_goostring.cpp
+++ b/qt5/tests/check_goostring.cpp
@@ -64,59 +64,59 @@ void TestGooString::testInsert()
 void TestGooString::testFormat()
 {
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF));
         QCOMPARE(goo->c_str(), "1,f");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA));
         QCOMPARE(goo->c_str(), "10,a,A,12,1010,          ");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA));
         QCOMPARE(goo->c_str(), "-10,-a,-A,-12,-1010");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}", 'T', (char)'E', (short)'S', (int)'T'));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}", 'T', (char)'E', (short)'S', (int)'T'));
         QCOMPARE(goo->c_str(), "TEST");
 
-        const QScopedPointer<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.data()));
+        const std::unique_ptr<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.get()));
         QCOMPARE(goo2->c_str(), "TEST TEST");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}", UINT_MAX, INT_MAX, INT_MIN));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}", UINT_MAX, INT_MAX, INT_MIN));
         const QByteArray expected = QStringLiteral("%1 %2 %3").arg(UINT_MAX).arg(INT_MAX).arg(INT_MIN).toLatin1();
         QCOMPARE(goo->c_str(), expected.constData());
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}", ULONG_MAX, LONG_MAX, LONG_MIN));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}", ULONG_MAX, LONG_MAX, LONG_MIN));
         const QByteArray expected = QStringLiteral("%1 %2 %3").arg(ULONG_MAX).arg(LONG_MAX).arg(LONG_MIN).toLatin1();
         QCOMPARE(goo->c_str(), expected.constData());
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}", ULLONG_MAX, LLONG_MAX, LLONG_MIN));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}", ULLONG_MAX, LLONG_MAX, LLONG_MIN));
         const QByteArray expected = QStringLiteral("%1 %2 %3").arg(ULLONG_MAX).arg(LLONG_MAX).arg(LLONG_MIN).toLatin1();
         QCOMPARE(goo->c_str(), expected.constData());
     }
     {
-        const QScopedPointer<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012));
-        const QScopedPointer<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f));
+        const std::unique_ptr<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012));
+        const std::unique_ptr<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f));
         QCOMPARE(gooD->c_str(), "1.0 1 1 | 0.0 0 0.01");
         QCOMPARE(gooF->c_str(), "1.0 1 1 | 0.0 0 0.01");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012));
         QCOMPARE(goo->c_str(), "0.0120 0.012 0.012");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1));
+        const std::unique_ptr<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1));
         QCOMPARE(goo->c_str(), "{ SomeText 1 }");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2));
+        const std::unique_ptr<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2));
         QCOMPARE(goo->c_str(), "{{ { SomeText 2");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3));
+        const std::unique_ptr<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3));
         QCOMPARE(goo->c_str(), "SomeText 3 } }}");
     }
 }
diff --git a/qt6/tests/check_annotations.cpp b/qt6/tests/check_annotations.cpp
index 478c2a9b..ca00d472 100644
--- a/qt6/tests/check_annotations.cpp
+++ b/qt6/tests/check_annotations.cpp
@@ -35,9 +35,8 @@ void TestAnnotations::checkQColorPrecision()
     bool precisionOk = true;
     for (int i = std::numeric_limits<uint16_t>::min(); i <= std::numeric_limits<uint16_t>::max(); i++) {
         double normalized = static_cast<uint16_t>(i) / static_cast<double>(std::numeric_limits<uint16_t>::max());
-        GooString *serialized = GooString::format("{0:.5f}", normalized);
+        const std::unique_ptr<GooString> serialized = GooString::format("{0:.5f}", normalized);
         double deserialized = gatof(serialized->c_str());
-        delete serialized;
         uint16_t denormalized = std::round(deserialized * std::numeric_limits<uint16_t>::max());
         if (static_cast<uint16_t>(i) != denormalized) {
             precisionOk = false;
diff --git a/qt6/tests/check_goostring.cpp b/qt6/tests/check_goostring.cpp
index 4a07cc6d..cfb14c2a 100644
--- a/qt6/tests/check_goostring.cpp
+++ b/qt6/tests/check_goostring.cpp
@@ -64,59 +64,59 @@ void TestGooString::testInsert()
 void TestGooString::testFormat()
 {
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF));
         QCOMPARE(goo->c_str(), "1,f");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA));
         QCOMPARE(goo->c_str(), "10,a,A,12,1010,          ");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA));
         QCOMPARE(goo->c_str(), "-10,-a,-A,-12,-1010");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}", 'T', (char)'E', (short)'S', (int)'T'));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}", 'T', (char)'E', (short)'S', (int)'T'));
         QCOMPARE(goo->c_str(), "TEST");
 
-        const QScopedPointer<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.data()));
+        const std::unique_ptr<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.get()));
         QCOMPARE(goo2->c_str(), "TEST TEST");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}", UINT_MAX, INT_MAX, INT_MIN));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}", UINT_MAX, INT_MAX, INT_MIN));
         const QByteArray expected = QStringLiteral("%1 %2 %3").arg(UINT_MAX).arg(INT_MAX).arg(INT_MIN).toLatin1();
         QCOMPARE(goo->c_str(), expected.constData());
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}", ULONG_MAX, LONG_MAX, LONG_MIN));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}", ULONG_MAX, LONG_MAX, LONG_MIN));
         const QByteArray expected = QStringLiteral("%1 %2 %3").arg(ULONG_MAX).arg(LONG_MAX).arg(LONG_MIN).toLatin1();
         QCOMPARE(goo->c_str(), expected.constData());
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}", ULLONG_MAX, LLONG_MAX, LLONG_MIN));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}", ULLONG_MAX, LLONG_MAX, LLONG_MIN));
         const QByteArray expected = QStringLiteral("%1 %2 %3").arg(ULLONG_MAX).arg(LLONG_MAX).arg(LLONG_MIN).toLatin1();
         QCOMPARE(goo->c_str(), expected.constData());
     }
     {
-        const QScopedPointer<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012));
-        const QScopedPointer<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f));
+        const std::unique_ptr<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012));
+        const std::unique_ptr<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f));
         QCOMPARE(gooD->c_str(), "1.0 1 1 | 0.0 0 0.01");
         QCOMPARE(gooF->c_str(), "1.0 1 1 | 0.0 0 0.01");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012));
+        const std::unique_ptr<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012));
         QCOMPARE(goo->c_str(), "0.0120 0.012 0.012");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1));
+        const std::unique_ptr<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1));
         QCOMPARE(goo->c_str(), "{ SomeText 1 }");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2));
+        const std::unique_ptr<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2));
         QCOMPARE(goo->c_str(), "{{ { SomeText 2");
     }
     {
-        const QScopedPointer<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3));
+        const std::unique_ptr<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3));
         QCOMPARE(goo->c_str(), "SomeText 3 } }}");
     }
 }
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 23ceec57..8a16e008 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -88,18 +88,18 @@
 class HtmlImage
 {
 public:
-    HtmlImage(GooString *_fName, GfxState *state) : fName(_fName)
+    HtmlImage(std::unique_ptr<GooString> &&_fName, GfxState *state) : fName(std::move(_fName))
     {
         state->transform(0, 0, &xMin, &yMax);
         state->transform(1, 1, &xMax, &yMin);
     }
-    ~HtmlImage() { delete fName; }
+    ~HtmlImage() = default;
     HtmlImage(const HtmlImage &) = delete;
     HtmlImage &operator=(const HtmlImage &) = delete;
 
     double xMin, xMax; // image x coordinates
     double yMin, yMax; // image y coordinates
-    GooString *fName; // image file name
+    std::unique_ptr<GooString> fName; // image file name
 };
 
 // returns true if x is closer to y than x is to z
@@ -124,7 +124,6 @@ extern bool noMerge;
 extern double wordBreakThreshold;
 
 static bool debug = false;
-static GooString *gstr_buff0 = nullptr; // a workspace in which I format strings
 
 #if 0
 static GooString* Dirname(GooString* str){
@@ -138,33 +137,24 @@ static GooString* Dirname(GooString* str){
 }
 #endif
 
-static const char *print_matrix(const double *mat)
+static std::unique_ptr<GooString> print_matrix(const double *mat)
 {
-    delete gstr_buff0;
-
-    gstr_buff0 = GooString::format("[{0:g} {1:g} {2:g} {3:g} {4:g} {5:g}]", *mat, mat[1], mat[2], mat[3], mat[4], mat[5]);
-    return gstr_buff0->c_str();
+    return GooString::format("[{0:g} {1:g} {2:g} {3:g} {4:g} {5:g}]", *mat, mat[1], mat[2], mat[3], mat[4], mat[5]);
 }
 
-static const char *print_uni_str(const Unicode *u, const unsigned uLen)
+static std::unique_ptr<GooString> print_uni_str(const Unicode *u, const unsigned uLen)
 {
-    GooString *gstr_buff1 = nullptr;
-
-    delete gstr_buff0;
-
     if (!uLen) {
-        return "";
+        return std::make_unique<GooString>("");
     }
-    gstr_buff0 = GooString::format("{0:c}", (*u < 0x7F ? *u & 0xFF : '?'));
+    std::unique_ptr<GooString> gstr_buff0 = GooString::format("{0:c}", (*u < 0x7F ? *u & 0xFF : '?'));
     for (unsigned i = 1; i < uLen; i++) {
         if (u[i] < 0x7F) {
-            gstr_buff1 = gstr_buff0->append(u[i] < 0x7F ? static_cast<char>(u[i]) & 0xFF : '?');
-            delete gstr_buff0;
-            gstr_buff0 = gstr_buff1;
+            gstr_buff0->append(u[i] < 0x7F ? static_cast<char>(u[i]) & 0xFF : '?');
         }
     }
 
-    return gstr_buff0->c_str();
+    return gstr_buff0;
 }
 
 //------------------------------------------------------------------------
@@ -198,16 +188,16 @@ HtmlString::HtmlString(GfxState *state, double fontSize, HtmlFontAccu *_fonts) :
             // browser rotates the opposite way
             // so flip the sign of the angle -> sin() components change sign
             if (debug) {
-                std::cerr << DEBUG << "before transform: " << print_matrix(normalizedMatrix) << std::endl;
+                std::cerr << DEBUG << "before transform: " << print_matrix(normalizedMatrix)->c_str() << std::endl;
             }
             normalizedMatrix[1] *= -1;
             normalizedMatrix[2] *= -1;
             if (debug) {
-                std::cerr << DEBUG << "after reflecting angle: " << print_matrix(normalizedMatrix) << std::endl;
+                std::cerr << DEBUG << "after reflecting angle: " << print_matrix(normalizedMatrix)->c_str() << std::endl;
             }
             normalizeRotMat(normalizedMatrix);
             if (debug) {
-                std::cerr << DEBUG << "after norm: " << print_matrix(normalizedMatrix) << std::endl;
+                std::cerr << DEBUG << "after norm: " << print_matrix(normalizedMatrix)->c_str() << std::endl;
             }
             hfont.setRotMat(normalizedMatrix);
         }
@@ -377,8 +367,8 @@ void HtmlPage::addChar(GfxState *state, double x, double y, double dx, double dy
         // sin q is zero iff there is no rotation, or 180 deg. rotation;
         // for 180 rotation, cos q will be negative
         if (text_mat[0] < 0 || !is_within(text_mat[1], .1, 0)) {
-            std::cerr << DEBUG << "rotation matrix for \"" << print_uni_str(u, uLen) << '"' << std::endl;
-            std::cerr << "text " << print_matrix(state->getTextMat());
+            std::cerr << DEBUG << "rotation matrix for \"" << print_uni_str(u, uLen)->c_str() << '"' << std::endl;
+            std::cerr << "text " << print_matrix(state->getTextMat())->c_str();
         }
     }
     if (n > 0 && // don't start a new string, unless there is already a string
@@ -991,9 +981,9 @@ void HtmlPage::setDocName(const char *fname)
     DocName = new GooString(fname);
 }
 
-void HtmlPage::addImage(GooString *fname, GfxState *state)
+void HtmlPage::addImage(std::unique_ptr<GooString> &&fname, GfxState *state)
 {
-    HtmlImage *img = new HtmlImage(fname, state);
+    HtmlImage *img = new HtmlImage(std::move(fname), state);
     imgList.push_back(img);
 }
 
@@ -1314,11 +1304,10 @@ void HtmlOutputDev::drawJpegImage(GfxState *state, Stream *str)
     int c;
 
     // open the image file
-    GooString *fName = createImageFileName("jpg");
+    std::unique_ptr<GooString> fName = createImageFileName("jpg");
     f1 = dataUrls ? ims.open("wb") : fopen(fName->c_str(), "wb");
     if (!f1) {
-        error(errIO, -1, "Couldn't open image file '{0:t}'", fName);
-        delete fName;
+        error(errIO, -1, "Couldn't open image file '{0:t}'", fName.get());
         return;
     }
 
@@ -1334,10 +1323,9 @@ void HtmlOutputDev::drawJpegImage(GfxState *state, Stream *str)
     fclose(f1);
 
     if (dataUrls) {
-        delete fName;
-        fName = new GooString(std::string("data:image/jpeg;base64,") + gbase64Encode(ims.getBuffer()));
+        fName = std::make_unique<GooString>(std::string("data:image/jpeg;base64,") + gbase64Encode(ims.getBuffer()));
     }
-    pages->addImage(fName, state);
+    pages->addImage(std::move(fName), state);
 }
 
 void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool isMask)
@@ -1352,18 +1340,17 @@ void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int he
     }
 
     // open the image file
-    GooString *fName = createImageFileName("png");
+    std::unique_ptr<GooString> fName = createImageFileName("png");
     f1 = dataUrls ? ims.open("wb") : fopen(fName->c_str(), "wb");
     if (!f1) {
-        error(errIO, -1, "Couldn't open image file '{0:t}'", fName);
-        delete fName;
+        error(errIO, -1, "Couldn't open image file '{0:t}'", fName.get());
         return;
     }
 
     PNGWriter *writer = new PNGWriter(isMask ? PNGWriter::MONOCHROME : PNGWriter::RGB);
     // TODO can we calculate the resolution of the image?
     if (!writer->init(f1, width, height, 72, 72)) {
-        error(errInternal, -1, "Can't init PNG for image '{0:t}'", fName);
+        error(errInternal, -1, "Can't init PNG for image '{0:t}'", fName.get());
         delete writer;
         fclose(f1);
         return;
@@ -1385,8 +1372,7 @@ void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int he
             // Convert into a PNG row
             p = imgStr->getLine();
             if (!p) {
-                error(errIO, -1, "Failed to read PNG. '{0:t}' will be incorrect", fName);
-                delete fName;
+                error(errIO, -1, "Failed to read PNG. '{0:t}' will be incorrect", fName.get());
                 gfree(row);
                 delete writer;
                 delete imgStr;
@@ -1403,7 +1389,7 @@ void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int he
             }
 
             if (!writer->writeRow(row_pointer)) {
-                error(errIO, -1, "Failed to write into PNG '{0:t}'", fName);
+                error(errIO, -1, "Failed to write into PNG '{0:t}'", fName.get());
                 delete writer;
                 delete imgStr;
                 fclose(f1);
@@ -1440,7 +1426,7 @@ void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int he
             }
 
             if (!writer->writeRow(&png_row)) {
-                error(errIO, -1, "Failed to write into PNG '{0:t}'", fName);
+                error(errIO, -1, "Failed to write into PNG '{0:t}'", fName.get());
                 delete writer;
                 fclose(f1);
                 gfree(png_row);
@@ -1458,16 +1444,15 @@ void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int he
     fclose(f1);
 
     if (dataUrls) {
-        delete fName;
-        fName = new GooString(std::string("data:image/png;base64,") + gbase64Encode(ims.getBuffer()));
+        fName = std::make_unique<GooString>(std::string("data:image/png;base64,") + gbase64Encode(ims.getBuffer()));
     }
-    pages->addImage(fName, state);
+    pages->addImage(std::move(fName), state);
 #else
     return;
 #endif
 }
 
-GooString *HtmlOutputDev::createImageFileName(const char *ext)
+std::unique_ptr<GooString> HtmlOutputDev::createImageFileName(const char *ext)
 {
     return GooString::format("{0:s}-{1:d}_{2:d}.{3:s}", Docname->c_str(), pageNum, pages->getNumImages() + 1, ext);
 }
diff --git a/utils/HtmlOutputDev.h b/utils/HtmlOutputDev.h
index c95a05f4..c7b08d15 100644
--- a/utils/HtmlOutputDev.h
+++ b/utils/HtmlOutputDev.h
@@ -14,7 +14,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2006, 2007, 2009, 2012, 2018-2021 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2006, 2007, 2009, 2012, 2018-2022 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2008, 2009 Warren Toomey <wkt at tuhs.org>
 // Copyright (C) 2009, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
@@ -144,7 +144,7 @@ public:
     void AddLink(const HtmlLink &x) { links->AddLink(x); }
 
     // add an image to the current page
-    void addImage(GooString *fname, GfxState *state);
+    void addImage(std::unique_ptr<GooString> &&fname, GfxState *state);
 
     // number of images on the current page
     int getNumImages() { return imgList.size(); }
@@ -294,7 +294,7 @@ private:
     int getOutlinePageNum(OutlineItem *item);
     void drawJpegImage(GfxState *state, Stream *str);
     void drawPngImage(GfxState *state, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool isMask = false);
-    GooString *createImageFileName(const char *ext);
+    std::unique_ptr<GooString> createImageFileName(const char *ext);
 
     FILE *fContentsFrame;
     FILE *page; // html file
diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc
index d496592a..6effd9d4 100644
--- a/utils/pdfsig.cc
+++ b/utils/pdfsig.cc
@@ -116,14 +116,12 @@ static bool dumpSignature(int sig_num, int sigCount, FormFieldSignature *s, cons
     // We want format to be {0:s}.sig{1:Xd} where X is sigCountLength
     // since { is the magic character to replace things we need to put it twice where
     // we don't want it to be replaced
-    GooString *format = GooString::format("{{0:s}}.sig{{1:{0:d}d}}", sigCountLength);
-    GooString *path = GooString::format(format->c_str(), gbasename(filename).c_str(), sig_num);
+    const std::unique_ptr<GooString> format = GooString::format("{{0:s}}.sig{{1:{0:d}d}}", sigCountLength);
+    const std::unique_ptr<GooString> path = GooString::format(format->c_str(), gbasename(filename).c_str(), sig_num);
     printf("Signature #%d (%u bytes) => %s\n", sig_num, signature->getLength(), path->c_str());
     std::ofstream outfile(path->c_str(), std::ofstream::binary);
     outfile.write(signature->c_str(), signature->getLength());
     outfile.close();
-    delete format;
-    delete path;
 
     return true;
 }
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index 88a2a0b0..97b141a2 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -345,7 +345,6 @@ int main(int argc, char *argv[])
     }
 
     if ((complexMode || singleHtml) && !xml && !ignore) {
-        GooString *imgFileName = nullptr;
         // White paper color
         SplashColor color;
         color[0] = color[1] = color[2] = 255;
@@ -360,11 +359,10 @@ int main(int argc, char *argv[])
             doc->displayPage(splashOut, pg, 72 * scale, 72 * scale, 0, true, false, false);
             SplashBitmap *bitmap = splashOut->getBitmap();
 
-            imgFileName = GooString::format("{0:s}{1:03d}.{2:s}", htmlFileName->c_str(), pg, extension);
+            const std::unique_ptr<GooString> imgFileName = GooString::format("{0:s}{1:03d}.{2:s}", htmlFileName->c_str(), pg, extension);
             auto f1 = dataUrls ? imf.open("wb") : fopen(imgFileName->c_str(), "wb");
             if (!f1) {
                 fprintf(stderr, "Could not open %s\n", imgFileName->c_str());
-                delete imgFileName;
                 continue;
             }
             bitmap->writeImgFile(format, f1, 72 * scale, 72 * scale);
@@ -374,7 +372,6 @@ int main(int argc, char *argv[])
             } else {
                 htmlOut->addBackgroundImage(gbasename(imgFileName->c_str()));
             }
-            delete imgFileName;
         }
 
         delete splashOut;


More information about the poppler mailing list