Skip to content

Fix memory leak in GetContext() in jxl_cms.cc - #4663

Merged
eustas merged 4 commits into
libjxl:mainfrom
rootvector2:memory-leak-cms-context
Mar 10, 2026
Merged

eustas merged 4 commits into
libjxl:mainfrom
rootvector2:memory-leak-cms-context

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

Description

Fix memory leak in GetContext() in jxl_cms.cc where cmsCreateContext allocates a CMS context per thread but cmsDeleteContext is never called on thread exit.

Replaced raw void* with std::unique_ptr using a custom ContextDeleter, following the existing RAII pattern (ProfileDeleter, TransformDeleter, CurveDeleter) in the same file.

Fixes #4166

@eustas eustas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, modulo missing space in line 808.

@eustas

eustas commented Mar 10, 2026

Copy link
Copy Markdown
Member

BTW, the other place where cmsContext is created would need similar change (load_jxl.cc)... But there it is wildly wrong - one context is shared between multiple threads... Creating an issue now, could be addressed later.

@rootvector2

Copy link
Copy Markdown
Contributor Author

LGTM, modulo missing space in line 808.

done

@eustas
eustas enabled auto-merge March 10, 2026 08:20
@eustas

eustas commented Mar 10, 2026

Copy link
Copy Markdown
Member

Thanks!

@eustas
eustas added this pull request to the merge queue Mar 10, 2026
Merged via the queue into libjxl:main with commit add4945 Mar 10, 2026
117 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in jxl_cms.cc

2 participants