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