summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarti Maria <marti.maria@littlecms.com>2022-11-12 20:00:46 +0100
committerMarti Maria <marti.maria@littlecms.com>2022-11-12 20:00:46 +0100
commita9e4601ceb3a185d4f78cc0cfbd285cf0c399e9d (patch)
treeac9b468461c97c0dd5b24cdb3c7c3c3702c68de1 /src
parent5cab2e5a12a069d1c270f16561c02b47ad664025 (diff)
downloadlcms2-a9e4601ceb3a185d4f78cc0cfbd285cf0c399e9d.tar.gz
fix memory corruption when unregistering plugins
unregistering plugins twice may corrupt memory. This commit fixes that.
Diffstat (limited to 'src')
-rw-r--r--src/cmsplugin.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/cmsplugin.c b/src/cmsplugin.c
index 7d038d2..1d8c358 100644
--- a/src/cmsplugin.c
+++ b/src/cmsplugin.c
@@ -795,9 +795,7 @@ void* _cmsContextGetClientChunk(cmsContext ContextID, _cmsMemoryClient mc)
// many different plug-ins simultaneously, then there is no way to
// identify which plug-in to unregister.
void CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID)
-{
- struct _cmsContext_struct* ctx = _cmsGetContext(ContextID);
-
+{
_cmsRegisterMemHandlerPlugin(ContextID, NULL);
_cmsRegisterInterpPlugin(ContextID, NULL);
_cmsRegisterTagTypePlugin(ContextID, NULL);
@@ -811,9 +809,6 @@ void CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID)
_cmsRegisterMutexPlugin(ContextID, NULL);
_cmsRegisterParallelizationPlugin(ContextID, NULL);
- if (ctx->MemPool != NULL)
- _cmsSubAllocDestroy(ctx->MemPool);
- ctx->MemPool = NULL;
}
@@ -981,7 +976,14 @@ cmsContext CMSEXPORT cmsDupContext(cmsContext ContextID, void* NewUserData)
// The ContextID can no longer be used in any THR operation.
void CMSEXPORT cmsDeleteContext(cmsContext ContextID)
{
- if (ContextID != NULL) {
+ if (ContextID == NULL) {
+
+ cmsUnregisterPlugins();
+ if (globalContext.MemPool != NULL)
+ _cmsSubAllocDestroy(globalContext.MemPool);
+ globalContext.MemPool = NULL;
+ }
+ else {
struct _cmsContext_struct* ctx = (struct _cmsContext_struct*) ContextID;
struct _cmsContext_struct fakeContext;