From e07c8b4784234383cb5ddcf1133ea91a772506e2 Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Tue, 1 Jan 2019 10:54:40 +0100 Subject: [PATCH] Avoid global display profile state becoming an uncontrolled memory leak by enforcing single initialization. Closes #654 --- poppler/GfxState.cc | 9 +++++++++ qt5/src/poppler-qt5.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index 87b7ce03..4e3ccbfd 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -226,6 +226,10 @@ static unsigned int getCMSNChannels(cmsColorSpaceSignature cs); static cmsHPROFILE loadColorProfile(const char *fileName); void GfxColorSpace::setDisplayProfile(void *displayProfileA) { + if (displayProfile != nullptr) { + error(errInternal, -1, "The display color profile can only be set once before any rendering is done."); + return; + } displayProfile = displayProfileA; if (displayProfile != nullptr) { cmsHTRANSFORM transform; @@ -249,6 +253,11 @@ void GfxColorSpace::setDisplayProfile(void *displayProfileA) { } void GfxColorSpace::setDisplayProfileName(GooString *name) { + if (displayProfile != nullptr) { + error(errInternal, -1, "The display color profile can only be set before any rendering is done."); + return; + } + delete displayProfileName; displayProfileName = name->copy(); } diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index 4f06c47e..ddac7dfb 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -1102,6 +1102,8 @@ delete it; \param outputProfileA is a \c cmsHPROFILE of the LCMS library. + \note This should be called before any rendering happens and only once during the lifetime of the current process. + \since 0.12 */ void setColorDisplayProfile(void *outputProfileA); @@ -1110,6 +1112,8 @@ delete it; \param name is the name of the display profile to set. + \note This should be called before any rendering happens. + \since 0.12 */ void setColorDisplayProfileName(const QString &name); -- 2.20.1