From f3da0a43f59d0d49a912f46c51f44432087d782a Mon Sep 17 00:00:00 2001
From: Sebastian Rasmussen <sebras@gmail.com>
Date: Mon, 1 Oct 2018 18:06:16 +0800
Subject: Keep cmm instance around until all colorspaces have been dropped.

By setting ctx->cmm_instance == NULL we actively made sure that
fz_cmm_fin_profile() would never call ->fin_profile() to actually
clean up the ICC profiles.

This could be triggered by doing mutool draw -N even without a
file name, triggering a memory leak.
---
 source/fitz/colorspace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'source/fitz')

diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c
index 27072a49..55f2f080 100644
--- a/source/fitz/colorspace.c
+++ b/source/fitz/colorspace.c
@@ -835,7 +835,6 @@ void fz_set_cmm_engine(fz_context *ctx, const fz_cmm_engine *engine)
 	if (cct->cmm == engine)
 		return;
 
-	fz_drop_cmm_context(ctx);
 	fz_drop_colorspace(ctx, cct->gray);
 	fz_drop_colorspace(ctx, cct->rgb);
 	fz_drop_colorspace(ctx, cct->bgr);
@@ -846,8 +845,12 @@ void fz_set_cmm_engine(fz_context *ctx, const fz_cmm_engine *engine)
 	cct->bgr = NULL;
 	cct->cmyk = NULL;
 	cct->lab = NULL;
+
+	fz_drop_cmm_context(ctx);
 	cct->cmm = engine;
+
 	fz_new_cmm_context(ctx);
+
 	if (engine)
 	{
 		cct->gray = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_GRAY, NULL);
-- 
cgit v1.2.3