Repository navigation
libshaderc_util: eliminate static mutex heap leak in GlslangInitializer (fixes #1473) - #1609
Open
jdymitarai wants to merge 1 commit into
Open
jdymitarai wants to merge 1 commit into
jdymitarai wants to merge 1 commit into
Conversation
…er (fixes google#1473) GlslangInitializer allocated a heap std::mutex via new to synchronize glslang initialization and finalization while deferring construction until first use. Because the allocated pointer was deliberately never deleted to avoid racing destructor calls, it leaked 80 bytes of heap memory on every run, surfacing in leak sanitizers and custom debug allocators. Replacing the raw heap pointer with a function-local static mutex reference achieves thread-safe deferred initialization under C++11 semantics without dynamic memory allocation, eliminating the memory leak while preserving concurrency guarantees across compiler instances. Signed-off-by: jdymitarai <o10040115@gmail.com>
dneto0
requested changes
Oct 19, 2026
dneto0
approved these changes
Oct 20, 2026
dneto0
left a comment
Collaborator
There was a problem hiding this comment.
This is a net win: going from
- a function-scope static std::mutex
- a new'd std::mutex that is leaked
to:
- a function-scope static std::mutex
That's a net win, adding no dependencies.
thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In GlslangInitializer, a process-wide mutex was dynamically allocated on the heap via new to synchronize glslang initialization without triggering static construction before main. Because the pointer was never deleted to prevent racing destructor calls, it produced an 80-byte heap memory leak reported by leak checkers whenever compilers were initialized and released.
Replacing the raw heap pointer with a function-local static mutex reference achieves deferred thread-safe initialization under C++11 semantics without heap allocation. This resolves the memory leak while preserving concurrency guarantees across multiple compiler instances. Verified with all 61 tests passing cleanly under ctest.