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