Skip to content

libshaderc_util: eliminate static mutex heap leak in GlslangInitializer (fixes #1473) - #1609

Open
jdymitarai wants to merge 1 commit into
google:mainfrom
jdymitarai:fix-glslang-initializer-mutex-leak-1473
Open

jdymitarai wants to merge 1 commit into
google:mainfrom
jdymitarai:fix-glslang-initializer-mutex-leak-1473

Conversation

@jdymitarai

Copy link
Copy Markdown

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.

…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>
Comment thread libshaderc_util/src/compiler.cc

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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!

@dneto0
dneto0 enabled auto-merge (rebase) October 20, 2026 19:03
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.

3 participants