diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-10-15 21:03:59 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-10-16 12:04:52 +0200 |
commit | 3503c03ece2fd912f4ba4767894eb97d8f9aae07 (patch) | |
tree | bc43d0d55e1f733370901faffe23ed4c67078573 /vcl/source/pdf | |
parent | 5b0ca23615c3d0aae7083147bc3bb5d61db26f5e (diff) |
pdfium: add an FPDFBitmap_Create() wrapper
Fixes a leak in PDFiumPage::getChecksum().
Change-Id: I57471a26702f1d3dd69e9e18a4067ce0e724e358
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104386
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl/source/pdf')
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 64fdd6a7e0d4..32c33580d1df 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -139,6 +139,21 @@ std::unique_ptr<PDFiumDocument> PDFium::openDocument(const void* pData, int nSiz return pPDFiumDocument; } +std::unique_ptr<PDFiumBitmap> PDFium::createBitmap(int nWidth, int nHeight, int nAlpha) +{ + std::unique_ptr<PDFiumBitmap> pPDFiumBitmap; + FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nWidth, nHeight, nAlpha); + if (!pPdfBitmap) + { + maLastError = "Failed to create bitmap"; + } + else + { + pPDFiumBitmap = std::make_unique<PDFiumBitmap>(pPdfBitmap); + } + return pPDFiumBitmap; +} + PDFiumDocument::PDFiumDocument(FPDF_DOCUMENT pPdfDocument) : mpPdfDocument(pPdfDocument) { @@ -377,7 +392,8 @@ BitmapChecksum PDFiumPage::getChecksum() { size_t nPageWidth = getWidth(); size_t nPageHeight = getHeight(); - FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1); + auto pPdfBitmap + = std::make_unique<PDFiumBitmap>(FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1)); if (!pPdfBitmap) { return 0; @@ -385,13 +401,15 @@ BitmapChecksum PDFiumPage::getChecksum() // Intentionally not using FPDF_ANNOT here, annotations/commenting is OK to not affect the // checksum, signature verification wants this. - FPDF_RenderPageBitmap(pPdfBitmap, mpPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight, + FPDF_RenderPageBitmap(pPdfBitmap->getPointer(), mpPage, /*start_x=*/0, /*start_y=*/0, + nPageWidth, nPageHeight, /*rotate=*/0, /*flags=*/0); Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24); { BitmapScopedWriteAccess pWriteAccess(aBitmap); - const auto pPdfBuffer = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap)); - const int nStride = FPDFBitmap_GetStride(pPdfBitmap); + const auto pPdfBuffer + = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap->getPointer())); + const int nStride = FPDFBitmap_GetStride(pPdfBitmap->getPointer()); for (size_t nRow = 0; nRow < nPageHeight; ++nRow) { ConstScanline pPdfLine = pPdfBuffer + (nStride * nRow); |