poppler/GlobalParams.cc | 6 +++--- poppler/GlobalParams.h | 4 ++-- poppler/GlobalParamsWin.cc | 21 +++++++++------------ 3 files changed, 14 insertions(+), 17 deletions(-)
New commits: commit 6a566e417b7c261252c8d3d83dd9b1c366f83194 Author: Albert Astals Cid <[email protected]> Date: Thu May 4 14:05:45 2023 +0200 Fix memory leak when looking for fonts in Windows diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index 82ac1fd8..2b899c92 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -1256,7 +1256,7 @@ void GlobalParams::setupBaseFonts(const char *dir) error(errConfig, -1, "No display font for '{0:s}'", displayFontTab[i].name); continue; } - addFontFile(fontName.get(), fileName.get()); + addFontFile(fontName->toStr(), fileName->toStr()); } } @@ -1372,10 +1372,10 @@ std::vector<std::string> GlobalParams::getEncodingNames() // functions to set parameters //------------------------------------------------------------------------ -void GlobalParams::addFontFile(const GooString *fontName, const GooString *path) +void GlobalParams::addFontFile(const std::string &fontName, const std::string &path) { globalParamsLocker(); - fontFiles[fontName->toStr()] = path->toStr(); + fontFiles[fontName] = path; } void GlobalParams::setTextEncoding(const char *encodingName) diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h index 67399f62..30b86ee1 100644 --- a/poppler/GlobalParams.h +++ b/poppler/GlobalParams.h @@ -13,7 +13,7 @@ // All changes made under the Poppler project to this file are licensed // under GPL version 2 or later // -// Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2022 Albert Astals Cid <[email protected]> +// Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2023 Albert Astals Cid <[email protected]> // Copyright (C) 2005 Jonathan Blandford <[email protected]> // Copyright (C) 2006 Takashi Iwai <[email protected]> // Copyright (C) 2006 Kristian Høgsberg <[email protected]> @@ -154,7 +154,7 @@ public: std::vector<std::string> getEncodingNames(); //----- functions to set parameters - void addFontFile(const GooString *fontName, const GooString *path); + void addFontFile(const std::string &fontName, const std::string &path); void setTextEncoding(const char *encodingName); void setPrintCommands(bool printCommandsA); void setProfileCommands(bool profileCommandsA); diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc index 93b47d03..d862775e 100644 --- a/poppler/GlobalParamsWin.cc +++ b/poppler/GlobalParamsWin.cc @@ -9,7 +9,7 @@ // Copyright (C) 2013, 2018, 2019 Adam Reichold <[email protected]> // Copyright (C) 2013 Dmytro Morgun <[email protected]> // Copyright (C) 2017 Christoph Cullmann <[email protected]> - // Copyright (C) 2017, 2018, 2020-2022 Albert Astals Cid <[email protected]> + // Copyright (C) 2017, 2018, 2020-2023 Albert Astals Cid <[email protected]> // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2019 Christian Persch <[email protected]> // Copyright (C) 2019 Oliver Sander <[email protected]> @@ -349,29 +349,26 @@ void GlobalParams::setupBaseFonts(const char *dir) if (fontFiles.count(displayFontTab[i].name) > 0) continue; - GooString *fontName = new GooString(displayFontTab[i].name); + const GooString fontName = GooString(displayFontTab[i].name); if (dir && displayFontTab[i].t1FileName) { - GooString *fontPath = appendToPath(new GooString(dir), displayFontTab[i].t1FileName); - if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath, ".pfb", ".pfa")->c_str())) { - addFontFile(fontName, fontPath); + const std::unique_ptr<GooString> fontPath(appendToPath(new GooString(dir), displayFontTab[i].t1FileName)); + if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath.get(), ".pfb", ".pfa")->c_str())) { + addFontFile(fontName.toStr(), fontPath->toStr()); continue; } - delete fontPath; } if (!winFontDir.empty() && displayFontTab[i].ttFileName) { - GooString *fontPath = appendToPath(new GooString(winFontDir), displayFontTab[i].ttFileName); - if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath, ".ttc", ".ttf")->c_str())) { - addFontFile(fontName, fontPath); + const std::unique_ptr<GooString> fontPath(appendToPath(new GooString(winFontDir), displayFontTab[i].ttFileName)); + if (FileExists(fontPath->c_str()) || FileExists(replaceSuffix(fontPath.get(), ".ttc", ".ttf")->c_str())) { + addFontFile(fontName.toStr(), fontPath->toStr()); continue; } - delete fontPath; } if (displayFontTab[i].warnIfMissing) { error(errSyntaxError, -1, "No display font for '{0:s}'", displayFontTab[i].name); - delete fontName; } } if (!winFontDir.empty()) { @@ -395,7 +392,7 @@ void GlobalParams::setupBaseFonts(const char *dir) if (obj2.isDict()) { Object obj3 = obj2.getDict()->lookup("Path"); if (obj3.isString()) - addFontFile(new GooString(obj1.getName()), obj3.getString()->copy()); + addFontFile(GooString(obj1.getName()).toStr(), obj3.getString()->toStr()); // Aliases } else if (obj2.isName()) { substFiles.emplace(obj1.getName(), obj2.getName());
