sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx |   30 +++++++++++----------
 1 file changed, 16 insertions(+), 14 deletions(-)

New commits:
commit 73b8736a14391fdf6f1310cc226e289333e0cc14
Author:     Đoàn Trần Công Danh <[email protected]>
AuthorDate: Sat Oct 18 20:45:27 2025 +0700
Commit:     Christian Lohmaier <[email protected]>
CommitDate: Tue Nov 4 13:12:53 2025 +0100

    Fix memory leak with poppler-25.10.0
    
    https://gerrit.libreoffice.org/c/core/+/192743, which fixes ftbfs with
    poppler 25.10.0, unfortunately introduced a memory leak when building
    with poppler 25.10.0 or later.  `pOwnerPasswordStr' and
    `pUserPasswordStr' ownership are supposed to be transfered to
    `pDocUnique', but is now orphaned.
    
    This change fix that said memory leak.
    
    Change-Id: I545d461c07f033b41a4276665483b44fa401a3bd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192645
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>
    (cherry picked from commit 89841fc69446a597b24b978344cd3c8d656aae09)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192934
    (cherry picked from commit 1d15201503d2d17ddede4aade0ef4666e64f862b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192948
    Tested-by: Christian Lohmaier <[email protected]>
    Tested-by: Ilmari Lauhakangas <[email protected]>
    Reviewed-by: Christian Lohmaier <[email protected]>

diff --git a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx 
b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
index 5bd78c78755e..76cd6262a46b 100644
--- a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
@@ -203,6 +203,22 @@ int main(int argc, char **argv)
                     // PDFDoc takes over ownership for all strings below
                     GooString* pFileName = new 
GooString(myStringToStdString(argv[1]));
 
+#if POPPLER_CHECK_VERSION(22, 6, 0)
+                    std::optional<GooString> ownerPasswordStr = {};
+                    if (aPwBuf[0] != 0) {
+                        ownerPasswordStr = 
std::make_optional<GooString>(aPwBuf);
+                    } else if (ownerPassword) {
+                        ownerPasswordStr = 
std::make_optional<GooString>(myStringToStdString(ownerPassword));
+                    }
+                    std::optional<GooString> userPasswordStr = {};
+                    if (aPwBuf[0] != 0) {
+                        userPasswordStr = 
std::make_optional<GooString>(aPwBuf);
+                    } else if (userPassword) {
+                        userPasswordStr = 
std::make_optional<GooString>(myStringToStdString(userPassword));
+                    }
+                    pDocUnique = std::make_unique<PDFDoc>(
+                        std::unique_ptr<GooString>(pFileName), 
ownerPasswordStr, userPasswordStr);
+#else
                     // check for password string(s)
                     GooString* pOwnerPasswordStr(aPwBuf[0] != 0
                                                  ? new GooString(aPwBuf)
@@ -214,20 +230,6 @@ int main(int argc, char **argv)
                                                 : (userPassword
                                                   ? new 
GooString(myStringToStdString(userPassword))
                                                   : nullptr));
-#if POPPLER_CHECK_VERSION(25, 10, 0)
-                    std::string sFileName(pFileName ? pFileName->toStr() : 
std::string());
-                    std::string sOwnerPasswordStr(pOwnerPasswordStr ? 
pOwnerPasswordStr->toStr() : std::string());
-                    std::string sUserPasswordStr(pUserPasswordStr ? 
pUserPasswordStr->toStr() : std::string());
-                    pDocUnique = std::unique_ptr<PDFDoc>(
-                        new PDFDoc(std::make_unique<GooString>(sFileName),
-                                   std::optional<GooString>(sOwnerPasswordStr),
-                                   
std::optional<GooString>(sUserPasswordStr)));
-#elif POPPLER_CHECK_VERSION(22, 6, 0)
-                    pDocUnique = std::unique_ptr<PDFDoc>(
-                        new PDFDoc(std::make_unique<GooString>(pFileName),
-                                   std::optional<GooString>(pOwnerPasswordStr),
-                                   
std::optional<GooString>(pUserPasswordStr)));
-#else
                     pDocUnique = std::unique_ptr<PDFDoc>(
                         new PDFDoc(pFileName, pOwnerPasswordStr, 
pUserPasswordStr));
 #endif

Reply via email to