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