summaryrefslogtreecommitdiff
path: root/base/gsicc_lcms2.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2022-01-19 11:25:34 +0000
committerRobin Watts <Robin.Watts@artifex.com>2022-01-19 14:47:43 +0000
commit9005cc3889222a4f5f0b77932e82cadf23c31151 (patch)
tree0633debaa1f1153f8f902f21fd55e60d4646a91d /base/gsicc_lcms2.c
parent10bc8def15b55415aa2776b675144ebc6ec9b4a8 (diff)
downloadghostpdl-9005cc3889222a4f5f0b77932e82cadf23c31151.tar.gz
Bug 704692: Fix gs_memory_t mismatch in cms alloc/free operations.
We generate a cmsContext to use at gs_lib_ctx startup, and then use that for every call into the cms. This encapsulates the gs_memory_t. For gs/pcl/xps etc this works well, as there is only a single interpreter, hence a single cmsContext. Unfortunately, for gpdl, each interpreter (potentially) gets its own cmsContext (certainly, the PS interpreter does). So on startup, when the PS interpreter initialises, it loads some default profiles and allocates them with one gs_memory_t. When we then come to read a profile using another interpreter (in this case, tiff), we read that using a different gs_memory_t. Because the icc_cache is stored in the device, it is shared across all the different interpreters, so we can end up with a mixture of blocks allocated with different gs_memory_t's. If we stored which gs_memory_t * had been used to allocate each block with the block we'd be fine - but we don't. Accordingly, when we closedown, blocks are 'freed' with the wrong gs_memory_t, causing problems. The simplest solution here (short of updating the memory wrappers that we pass into lcms2/lcms2mt to store gs_memory_t's in every block, with the attendant memory increase this would cause) is to move the cmsContext from gs_lib_ctx_t to the gs_lib_ctx core. In this way we only have a single cmsContext shared across all the different interpreters. This feels like the correct solution to me.
Diffstat (limited to 'base/gsicc_lcms2.c')
-rw-r--r--base/gsicc_lcms2.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/base/gsicc_lcms2.c b/base/gsicc_lcms2.c
index 9badb6dee..3c2d1d579 100644
--- a/base/gsicc_lcms2.c
+++ b/base/gsicc_lcms2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2021 Artifex Software, Inc.
+/* Copyright (C) 2001-2022 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -731,7 +731,7 @@ gscms_get_link_proof_devlink(gcmmhprofile_t lcms_srchandle,
}
/* Do any initialization if needed to the CMS */
-int
+void *
gscms_create(gs_memory_t *memory)
{
cmsContext ctx;
@@ -739,27 +739,26 @@ gscms_create(gs_memory_t *memory)
/* Set our own error handling function */
ctx = cmsCreateContext((void *)&gs_cms_memhandler, memory);
if (ctx == NULL)
- return_error(gs_error_VMerror);
+ return NULL;
#ifdef USE_LCMS2_LOCKING
cmsPluginTHR(ctx, (void *)&gs_cms_mutexhandler);
#endif
cmsSetLogErrorHandlerTHR(ctx, gscms_error);
- gs_lib_ctx_set_cms_context(memory, ctx);
- return 0;
+
+ return ctx;
}
/* Do any clean up when done with the CMS if needed */
void
-gscms_destroy(gs_memory_t *memory)
+gscms_destroy(void *cmsContext_)
{
- cmsContext ctx = gs_lib_ctx_get_cms_context(memory);
+ cmsContext ctx = (cmsContext)cmsContext_;
if (ctx == NULL)
return;
cmsDeleteContext(ctx);
- gs_lib_ctx_set_cms_context(memory, NULL);
}
/* Have the CMS release the link */