-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update CreateColorProfileFromLogColorSpace to steer people away from a memory leak
#2025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: docs
Are you sure you want to change the base?
Conversation
…om memory leak The documentation indicates that you should use `GlobalFree` on the value stored at the address given by `pProfile`. In other words, ```c BYTE* pProfile = NULL; CreateProfileFromLogColorSpaceW(..., &pProfile); GlobalFree((HGLOBAL)pProfile); ``` This is wrong, it is a memory leak. If you do this 65,536 times in a row then this method will start returning `ERROR_NOT_ENOUGH_MEMORY`. Apparently that's the maximum number of `HGLOBAL`s you can have. The correct pattern is this: ```c BYTE* pProfile = NULL; CreateProfileFromLogColorSpaceW(..., &pProfile); HGLOBAL hProfile = GlobalHandle(pProfile); GlobalFree(hProfile); ``` I ran into this issue while working on my desktop app. I had a bug in a caching layer that was causing my color profile caching to not work, so it was recreating the profile on every call into the cache. After using the app for a few minutes it would crash because I convert Win32 errors into .NET exceptions. cc @Sergio0694
|
@rickbrew : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change. |
CreateColorProfileFromLogColorSpaceW to steer people away from a memory leakCreateColorProfileFromLogColorSpace to steer people away from a memory leak
|
Note that the "wrong" case you mention, could be correct only if internally, they were using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes documentation that was instructing developers to use an incorrect memory management pattern that causes memory leaks when using CreateProfileFromLogColorSpace functions. The documentation previously suggested calling GlobalFree directly on the buffer pointer, but the correct approach is to first use GlobalHandle to get the handle, then free that handle.
- Updates the remarks section in both ASCII and Unicode function documentation to describe the correct memory management pattern
- Adds references to the
GlobalHandlefunction in the "See also" sections
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| nf-icm-createprofilefromlogcolorspacew.md | Updated Unicode version documentation with correct memory management instructions |
| nf-icm-createprofilefromlogcolorspacea.md | Updated ASCII version documentation with correct memory management instructions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
The documentation indicates that you should use
GlobalFreeon the value stored at the address given bypProfile.In other words,
This is wrong, it is a memory leak. If you do this 65,536 times in a row then this method will start returning
ERROR_NOT_ENOUGH_MEMORY. Apparently that's the maximum number ofHGLOBALs you can have.The correct pattern is this:
I ran into this issue while working on my desktop app. I had a bug in a caching layer that was causing my color profile caching to not work, so it was recreating the profile on every call into the cache. After using the app for a few minutes it would crash because I convert Win32 errors into .NET exceptions.
cc @Sergio0694