feat: allow freeing of ustring table for debugging cases#5213
Conversation
|
Another independent stab that is an alternate to #5193. This PR still establishes the same external API for requesting that the ustring table be cleaned up, but I change the absolute minimal amount of the existing code. |
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in shutdown-time cleanup path for the global ustring table so that leak-detection tools (e.g. valgrind) don’t report the intentionally-retained ustring storage as leaks. The cleanup is enabled either via OIIO::attribute("ustring:cleanup", 1) or the OIIO_USTRING_CLEANUP environment variable.
Changes:
- Introduce a global
oiio_ustring_cleanupflag (env-var initialized) and add optional teardown logic toustringtable destruction. - Wire the new
"ustring:cleanup"option intoOIIO::attribute()/OIIO::getattribute(). - Document the new attribute in the public API header.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/libutil/ustring.cpp |
Adds the cleanup flag and implements optional destruction/freeing of table entries and pools at exit. |
src/libOpenImageIO/imageio.cpp |
Exposes "ustring:cleanup" through global attribute/getattribute plumbing. |
src/include/OpenImageIO/imageio.h |
Documents the new global attribute. |
src/include/imageio_pvt.h |
Declares the exported cleanup flag for cross-library access. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This patch optionally frees the contents of the ustring table as the
process is exiting. It's triggered one of two ways:
- `OIIO::attribute("ustring:cleanup", 1);`
- Environment variable `OIIO_USTRING_CLEANUP=1`
If neither is used, the teardown won't happen, thus avoiding any
pointless work when it should be exiting the process.
The purpose of this is that when using certain debugging tools, the
ustring table (which only grows and never frees) looks like a memory
leak, even though it's by design. Someimes, it's useful to make it not
appear ot leak, and you are happy for a large table to spend time
pointlessly freeing all the data.
Fixes 3913
Signed-off-by: Larry Gritz <lg@larrygritz.com>
e2e216c to
6eb8e19
Compare
|
@fpsunflower Is this one more to your liking? It's more of a truly minimal modification to the existing ustring.cpp code. And @jreichel-nvidia, so sorry, but could you also try this one and verify that it squashes all the detectable leaks? |
This patch optionally frees the contents of the ustring table as the process is exiting. It's triggered one of two ways:
OIIO::attribute("ustring:cleanup", 1);OIIO_USTRING_CLEANUP=1If neither is used, the teardown won't happen, thus avoiding any pointless work when it should be exiting the process.
The purpose of this is that when using certain debugging tools, the ustring table (which only grows and never frees) looks like a memory leak, even though it's by design. Someimes, it's useful to make it not appear ot leak, and you are happy for a large table to spend time pointlessly freeing all the data.
Fixes #3913