Skip to content

Commit

Permalink
Add the possibility of duplicating a NULL context for cloning default…
Browse files Browse the repository at this point in the history
…s. Previously that was undefined behavior,

Fixes #462
  • Loading branch information
mm2 committed Oct 27, 2024
1 parent 47a261e commit c75a823
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cmsplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c75a823

Please sign in to comment.