Fix memory leak when poppler 25.10.0 support got added to libreoffice --- libreoffice-25.8.3.1/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx.~1~ 2025-10-22 08:04:25.000000000 -0400 +++ libreoffice-25.8.3.1/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx 2025-10-28 19:49:41.641374066 -0400 @@ -203,6 +203,22 @@ // PDFDoc takes over ownership for all strings below GooString* pFileName = new GooString(myStringToStdString(argv[1])); +#if POPPLER_CHECK_VERSION(22, 6, 0) + std::optional ownerPasswordStr = {}; + if (aPwBuf[0] != 0) { + ownerPasswordStr = std::make_optional(aPwBuf); + } else if (ownerPassword) { + ownerPasswordStr = std::make_optional(myStringToStdString(ownerPassword)); + } + std::optional userPasswordStr = {}; + if (aPwBuf[0] != 0) { + userPasswordStr = std::make_optional(aPwBuf); + } else if (userPassword) { + userPasswordStr = std::make_optional(myStringToStdString(userPassword)); + } + pDocUnique = std::make_unique( + std::unique_ptr(pFileName), ownerPasswordStr, userPasswordStr); +#else // check for password string(s) GooString* pOwnerPasswordStr(aPwBuf[0] != 0 ? new GooString(aPwBuf) @@ -214,20 +230,6 @@ : (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( - new PDFDoc(std::make_unique(sFileName), - std::optional(sOwnerPasswordStr), - std::optional(sUserPasswordStr))); -#elif POPPLER_CHECK_VERSION(22, 6, 0) - pDocUnique = std::unique_ptr( - new PDFDoc(std::make_unique(pFileName), - std::optional(pOwnerPasswordStr), - std::optional(pUserPasswordStr))); -#else pDocUnique = std::unique_ptr( new PDFDoc(pFileName, pOwnerPasswordStr, pUserPasswordStr)); #endif