vcl/headless/svpinst.cxx | 7 ++++--- vcl/headless/svpvd.cxx | 10 +++++++--- vcl/inc/headless/svpvd.hxx | 2 +- vcl/unx/gtk3/gtkinst.cxx | 7 ++++--- 4 files changed, 16 insertions(+), 10 deletions(-)
New commits: commit d2d01d5128b6c01bbf5bf3febb2c0ac18ebc7eda Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sat Aug 13 20:23:57 2022 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Sun Aug 14 12:57:38 2022 +0200 ofz#50202 Direct-leak detect and flag as error failure to sucessfully create a cairo surface Change-Id: I6981ec3058e37f4f4f196f6136f1d81865623c52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138238 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx index bf53dc24faf3..5a86826423e3 100644 --- a/vcl/headless/svpinst.cxx +++ b/vcl/headless/svpinst.cxx @@ -260,9 +260,10 @@ std::unique_ptr<SalVirtualDevice> SvpSalInstance::CreateVirtualDevice(SalGraphic (void)pGd; cairo_surface_t* pPreExistingTarget = nullptr; #endif - std::unique_ptr<SalVirtualDevice> pNew(new SvpSalVirtualDevice(pSvpSalGraphics->getSurface(), pPreExistingTarget)); - pNew->SetSize( nDX, nDY ); - return pNew; + std::unique_ptr<SalVirtualDevice> xNew(new SvpSalVirtualDevice(pSvpSalGraphics->getSurface(), pPreExistingTarget)); + if (!xNew->SetSize(nDX, nDY)) + xNew.reset(); + return xNew; } cairo_surface_t* get_underlying_cairo_surface(const VirtualDevice& rDevice) diff --git a/vcl/headless/svpvd.cxx b/vcl/headless/svpvd.cxx index 162bd78ec75a..ffbc3dc37190 100644 --- a/vcl/headless/svpvd.cxx +++ b/vcl/headless/svpvd.cxx @@ -69,7 +69,7 @@ bool SvpSalVirtualDevice::SetSize( tools::Long nNewDX, tools::Long nNewDY ) return SetSizeUsingBuffer(nNewDX, nNewDY, nullptr); } -void SvpSalVirtualDevice::CreateSurface(tools::Long nNewDX, tools::Long nNewDY, sal_uInt8 *const pBuffer) +bool SvpSalVirtualDevice::CreateSurface(tools::Long nNewDX, tools::Long nNewDY, sal_uInt8 *const pBuffer) { if (m_pSurface) { @@ -111,11 +111,14 @@ void SvpSalVirtualDevice::CreateSurface(tools::Long nNewDX, tools::Long nNewDY, } SAL_WARN_IF(cairo_surface_status(m_pSurface) != CAIRO_STATUS_SUCCESS, "vcl", "surface of size " << nNewDX << " by " << nNewDY << " creation failed with status of: " << cairo_status_to_string(cairo_surface_status(m_pSurface))); + return cairo_surface_status(m_pSurface) == CAIRO_STATUS_SUCCESS; } bool SvpSalVirtualDevice::SetSizeUsingBuffer( tools::Long nNewDX, tools::Long nNewDY, sal_uInt8 *const pBuffer) { + bool bSuccess = true; + if (nNewDX == 0) nNewDX = 1; if (nNewDY == 0) @@ -127,7 +130,7 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( tools::Long nNewDX, tools::Long nN m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY); if (m_bOwnsSurface) - CreateSurface(nNewDX, nNewDY, pBuffer); + bSuccess = CreateSurface(nNewDX, nNewDY, pBuffer); assert(m_pSurface); @@ -135,7 +138,8 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( tools::Long nNewDX, tools::Long nN for (auto const& graphic : m_aGraphics) graphic->setSurface(m_pSurface, m_aFrameSize); } - return true; + + return bSuccess; } tools::Long SvpSalVirtualDevice::GetWidth() const diff --git a/vcl/inc/headless/svpvd.hxx b/vcl/inc/headless/svpvd.hxx index ca9e38cee31a..f76b78c1df67 100644 --- a/vcl/inc/headless/svpvd.hxx +++ b/vcl/inc/headless/svpvd.hxx @@ -37,7 +37,7 @@ class VCL_DLLPUBLIC SvpSalVirtualDevice : public SalVirtualDevice basegfx::B2IVector m_aFrameSize; std::vector< SvpSalGraphics* > m_aGraphics; - void CreateSurface(tools::Long nNewDX, tools::Long nNewDY, sal_uInt8 *const pBuffer); + bool CreateSurface(tools::Long nNewDX, tools::Long nNewDY, sal_uInt8 *const pBuffer); protected: SvpSalGraphics* AddGraphics(SvpSalGraphics* aGraphics); diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index c434996c9552..74df879c85e1 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -383,9 +383,10 @@ std::unique_ptr<SalVirtualDevice> GtkInstance::CreateVirtualDevice( SalGraphics assert(pSvpSalGraphics); // tdf#127529 see SvpSalInstance::CreateVirtualDevice for the rare case of a non-null pPreExistingTarget cairo_surface_t* pPreExistingTarget = pGd ? static_cast<cairo_surface_t*>(pGd->pSurface) : nullptr; - std::unique_ptr<SalVirtualDevice> pNew(new SvpSalVirtualDevice(pSvpSalGraphics->getSurface(), pPreExistingTarget)); - pNew->SetSize( nDX, nDY ); - return pNew; + std::unique_ptr<SalVirtualDevice> xNew(new SvpSalVirtualDevice(pSvpSalGraphics->getSurface(), pPreExistingTarget)); + if (!xNew->SetSize(nDX, nDY)) + xNew.reset(); + return xNew; } std::shared_ptr<SalBitmap> GtkInstance::CreateSalBitmap()