Skip to content

Double Free Fix for 2026.07 - #78

Merged
dstover11 merged 1 commit into
2026.07from
stover/fix-gtest-double-free
Jul 17, 2026
Merged

Double Free Fix for 2026.07#78
dstover11 merged 1 commit into
2026.07from
stover/fix-gtest-double-free

Conversation

@dstover11

Copy link
Copy Markdown
Contributor

Fix double-free at test teardown by splitting GTest out of shared fileformatUtils

The *SanityTests binaries aborted at process exit on Linux with "double free or corruption (fasttop)". The tests themselves passed; the abort happened during static-destructor teardown (_dl_fini -> libfileformatUtils.so __cxa_finalize -> std::string dtor).

Root cause: GoogleTest is statically linked and was embedded into BOTH the shared libfileformatUtils.so (which compiled the test helper test.cpp and linked GTest::gtest PUBLIC) AND every test executable. GoogleTest's global command-line-flag std::strings therefore collapsed to a single address under the ELF flat namespace, but each module registered its own __cxa_atexit finalizer, so the one object's destructor ran twice -> double free. macOS (two-level namespace) and Windows were unaffected, which is why only the ubuntu-22.04 jobs failed.

Fix: move the test-only helper (test.cpp/test.h) into a new STATIC library fileformatUtilsTest that links GTest, and stop linking GTest into the shared fileformatUtils runtime library. GTest now lives only in the static helper and the test executables, so there is a single set of GTest globals per process and a single destructor. The test helper gets its own empty USDFFUTILSTEST_API macro since a static library linked directly into each executable needs no import/export decoration (this also keeps Windows /WX happy). All test targets that used the helper now link fileformatUtilsTest, which brings fileformatUtils in transitively.

…eformatUtils
The *SanityTests binaries aborted at process exit on Linux with
"double free or corruption (fasttop)". The tests themselves passed; the
abort happened during static-destructor teardown (_dl_fini ->
libfileformatUtils.so __cxa_finalize -> std::string dtor).
Root cause: GoogleTest is statically linked and was embedded into BOTH the
shared libfileformatUtils.so (which compiled the test helper test.cpp and
linked GTest::gtest PUBLIC) AND every test executable. GoogleTest's global
command-line-flag std::strings therefore collapsed to a single address under
the ELF flat namespace, but each module registered its own __cxa_atexit
finalizer, so the one object's destructor ran twice -> double free. macOS
(two-level namespace) and Windows were unaffected, which is why only the
ubuntu-22.04 jobs failed.
Fix: move the test-only helper (test.cpp/test.h) into a new STATIC library
fileformatUtilsTest that links GTest, and stop linking GTest into the shared
fileformatUtils runtime library. GTest now lives only in the static helper
and the test executables, so there is a single set of GTest globals per
process and a single destructor. The test helper gets its own empty
USDFFUTILSTEST_API macro since a static library linked directly into each
executable needs no import/export decoration (this also keeps Windows /WX
happy). All test targets that used the helper now link fileformatUtilsTest,
which brings fileformatUtils in transitively.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@jakes-adobejakes-adobe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice find!

@dstover11
dstover11 merged commit a8576db into 2026.07Jul 17, 2026
2 checks passed
@dstover11
dstover11 deleted the stover/fix-gtest-double-free branch July 17, 2026 19:29
Sign up for freeto 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.

2 participants

@dstover11@jakes-adobe