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