From c75a82336eeaa19c2632193c63d52c9435542182 Mon Sep 17 00:00:00 2001 From: Marti Maria Date: Sun, 27 Oct 2024 18:48:12 +0100 Subject: [PATCH] Add the possibility of duplicating a NULL context for cloning defaults. Previously that was undefined behavior, Fixes #462 --- src/cmsplugin.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmsplugin.c b/src/cmsplugin.c index 41b27999..36ac1b8c 100644 --- a/src/cmsplugin.c +++ b/src/cmsplugin.c @@ -906,7 +906,10 @@ cmsContext CMSEXPORT cmsDupContext(cmsContext ContextID, void* NewUserData) if (!InitContextMutex()) return NULL; // Setup default memory allocators - memcpy(&ctx->DefaultMemoryManager, &src->DefaultMemoryManager, sizeof(ctx->DefaultMemoryManager)); + if (ContextID == NULL) + _cmsInstallAllocFunctions(NULL, &ctx->DefaultMemoryManager); + else + memcpy(&ctx->DefaultMemoryManager, &src->DefaultMemoryManager, sizeof(ctx->DefaultMemoryManager)); // Maintain the linked list _cmsEnterCriticalSectionPrimitive(&_cmsContextPoolHeadMutex);