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