Skip to content

enabling address sanitization with an empty set of tests reports leaks on Linux w/ Swift 6.2.1 #521

@heckj

Description

@heckj

When running swift test on Linux, with address sanitization enabled, I'm getting an error about memory leaks.

This doesn't happen with macOS

Reproduction:

mkdir TempExample
cd TempExample
swift package init

# works in macOS
swift test --sanitize=address

# doesn't work in Linux
container run -it -c 4 -m 8g -v "$(pwd):/src" -w src/ swift:6.2 swift test --sanitize=address

Output from failure:

[1/1] Planning build
Building for debugging...
[1/1] Write swift-version-24593BA9C3E375BF.txt
Build complete! (0.10s)
Test Suite 'All tests' started at 2025-11-25 21:48:31.247
Test Suite 'debug.xctest' started at 2025-11-25 21:48:31.261
Test Suite 'debug.xctest' passed at 2025-11-25 21:48:31.262
	 Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds
Test Suite 'All tests' passed at 2025-11-25 21:48:31.262
	 Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds

=================================================================
==62==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0xaaaabf578560 in malloc /home/build-user/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0xffff9f65329c in swift_slowAlloc (/usr/lib/swift/linux/libswiftCore.so+0x3f329c) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #2 0xffff9f6536b8 in swift_allocObject (/usr/lib/swift/linux/libswiftCore.so+0x3f36b8) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #3 0xffff9de3aa70 in $s6XCTest0A8SuiteRunC4testAc2AC_tcfC (/usr/lib/swift/linux/libXCTest.so+0x2aa70) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #4 0xffff9de3bcc4 in $s6XCTestAAC3runyyF (/usr/lib/swift/linux/libXCTest.so+0x2bcc4) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #5 0xffff9de3707c in $s6XCTest7XCTMain_9arguments9observerss5Int32VSayAA0A4CaseCm04testF5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF (/usr/lib/swift/linux/libXCTest.so+0x2707c) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #6 0xffff9de37130 in $s6XCTest7XCTMainys5NeverOSayAA0A4CaseCm04testD5Class_SaySS_yAFKctG8allTeststGF (/usr/lib/swift/linux/libXCTest.so+0x27130) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #7 0xaaaabf5ff7d4 in $s23TempExamplePackageTests6RunnerV4mainyyFZ /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift:543:14
    #8 0xaaaabf5ff84c in $s23TempExamplePackageTests6RunnerV5$mainyyFZ /<compiler-generated>
    #9 0xaaaabf5ff864 in main /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift
    #10 0xffff9db584c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #11 0xffff9db58594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #12 0xaaaabf4ec32c in _start (/src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.xctest+0x5c32c) (BuildId: 835d26df23c8894a9125db6195006ce0aee2d284)

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0xaaaabf578560 in malloc /home/build-user/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0xffff9f65329c in swift_slowAlloc (/usr/lib/swift/linux/libswiftCore.so+0x3f329c) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #2 0xffff9f6536b8 in swift_allocObject (/usr/lib/swift/linux/libswiftCore.so+0x3f36b8) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #3 0xffff9de3aa70 in $s6XCTest0A8SuiteRunC4testAc2AC_tcfC (/usr/lib/swift/linux/libXCTest.so+0x2aa70) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #4 0xffff9de3bcc4 in $s6XCTestAAC3runyyF (/usr/lib/swift/linux/libXCTest.so+0x2bcc4) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #5 0xffff9de3a280 in $s6XCTest0A5SuiteC7performyyAA0A3RunCF (/usr/lib/swift/linux/libXCTest.so+0x2a280) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #6 0xffff9de3bd10 in $s6XCTestAAC3runyyF (/usr/lib/swift/linux/libXCTest.so+0x2bd10) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #7 0xffff9de3707c in $s6XCTest7XCTMain_9arguments9observerss5Int32VSayAA0A4CaseCm04testF5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF (/usr/lib/swift/linux/libXCTest.so+0x2707c) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #8 0xffff9de37130 in $s6XCTest7XCTMainys5NeverOSayAA0A4CaseCm04testD5Class_SaySS_yAFKctG8allTeststGF (/usr/lib/swift/linux/libXCTest.so+0x27130) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #9 0xaaaabf5ff7d4 in $s23TempExamplePackageTests6RunnerV4mainyyFZ /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift:543:14
    #10 0xaaaabf5ff84c in $s23TempExamplePackageTests6RunnerV5$mainyyFZ /<compiler-generated>
    #11 0xaaaabf5ff864 in main /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift
    #12 0xffff9db584c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #13 0xffff9db58594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #14 0xaaaabf4ec32c in _start (/src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.xctest+0x5c32c) (BuildId: 835d26df23c8894a9125db6195006ce0aee2d284)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0xaaaabf578560 in malloc /home/build-user/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0xffff9f65329c in swift_slowAlloc (/usr/lib/swift/linux/libswiftCore.so+0x3f329c) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #2 0xffff9f6536b8 in swift_allocObject (/usr/lib/swift/linux/libswiftCore.so+0x3f36b8) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #3 0xffff9de349cc in $s6XCTest11XCTMainMisc_9arguments9observersAA19TestSuiteOrExitCodeOSayAA0A4CaseCm04testK5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF crtstuff.c
    #4 0xffff9de36fa0 in $s6XCTest7XCTMain_9arguments9observerss5Int32VSayAA0A4CaseCm04testF5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF (/usr/lib/swift/linux/libXCTest.so+0x26fa0) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #5 0xffff9de37130 in $s6XCTest7XCTMainys5NeverOSayAA0A4CaseCm04testD5Class_SaySS_yAFKctG8allTeststGF (/usr/lib/swift/linux/libXCTest.so+0x27130) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #6 0xaaaabf5ff7d4 in $s23TempExamplePackageTests6RunnerV4mainyyFZ /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift:543:14
    #7 0xaaaabf5ff84c in $s23TempExamplePackageTests6RunnerV5$mainyyFZ /<compiler-generated>
    #8 0xaaaabf5ff864 in main /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift
    #9 0xffff9db584c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #10 0xffff9db58594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #11 0xaaaabf4ec32c in _start (/src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.xctest+0x5c32c) (BuildId: 835d26df23c8894a9125db6195006ce0aee2d284)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0xaaaabf578560 in malloc /home/build-user/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0xffff9f65329c in swift_slowAlloc (/usr/lib/swift/linux/libswiftCore.so+0x3f329c) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #2 0xffff9f6536b8 in swift_allocObject (/usr/lib/swift/linux/libswiftCore.so+0x3f36b8) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #3 0xffff9de34ab8 in $s6XCTest11XCTMainMisc_9arguments9observersAA19TestSuiteOrExitCodeOSayAA0A4CaseCm04testK5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF crtstuff.c
    #4 0xffff9de36fa0 in $s6XCTest7XCTMain_9arguments9observerss5Int32VSayAA0A4CaseCm04testF5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF (/usr/lib/swift/linux/libXCTest.so+0x26fa0) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #5 0xffff9de37130 in $s6XCTest7XCTMainys5NeverOSayAA0A4CaseCm04testD5Class_SaySS_yAFKctG8allTeststGF (/usr/lib/swift/linux/libXCTest.so+0x27130) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #6 0xaaaabf5ff7d4 in $s23TempExamplePackageTests6RunnerV4mainyyFZ /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift:543:14
    #7 0xaaaabf5ff84c in $s23TempExamplePackageTests6RunnerV5$mainyyFZ /<compiler-generated>
    #8 0xaaaabf5ff864 in main /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift
    #9 0xffff9db584c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #10 0xffff9db58594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #11 0xaaaabf4ec32c in _start (/src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.xctest+0x5c32c) (BuildId: 835d26df23c8894a9125db6195006ce0aee2d284)

Indirect leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0xaaaabf578560 in malloc /home/build-user/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0xffff9f65329c in swift_slowAlloc (/usr/lib/swift/linux/libswiftCore.so+0x3f329c) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #2 0xffff9f6536b8 in swift_allocObject (/usr/lib/swift/linux/libswiftCore.so+0x3f36b8) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #3 0xffff9f3bbeb4 in $ss22_ContiguousArrayBufferV20_consumeAndCreateNew14bufferIsUnique15minimumCapacity13growForAppendAByxGSb_SiSbtFSS5IndexV_Tg5Tm Swift.o
    #4 0xffff9f4ffe14 in $sSa034_makeUniqueAndReserveCapacityIfNotB0yyFyXl_Ts5 (/usr/lib/swift/linux/libswiftCore.so+0x29fe14) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #5 0xffff9de3a9f0 in $s6XCTest0A8SuiteRunC07addTestC0yyAA0aC0CF (/usr/lib/swift/linux/libXCTest.so+0x2a9f0) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #6 0xffff9de3a2a8 in $s6XCTest0A5SuiteC7performyyAA0A3RunCF (/usr/lib/swift/linux/libXCTest.so+0x2a2a8) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #7 0xffff9de3bd10 in $s6XCTestAAC3runyyF (/usr/lib/swift/linux/libXCTest.so+0x2bd10) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #8 0xffff9de3707c in $s6XCTest7XCTMain_9arguments9observerss5Int32VSayAA0A4CaseCm04testF5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF (/usr/lib/swift/linux/libXCTest.so+0x2707c) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #9 0xffff9de37130 in $s6XCTest7XCTMainys5NeverOSayAA0A4CaseCm04testD5Class_SaySS_yAFKctG8allTeststGF (/usr/lib/swift/linux/libXCTest.so+0x27130) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #10 0xaaaabf5ff7d4 in $s23TempExamplePackageTests6RunnerV4mainyyFZ /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift:543:14
    #11 0xaaaabf5ff84c in $s23TempExamplePackageTests6RunnerV5$mainyyFZ /<compiler-generated>
    #12 0xaaaabf5ff864 in main /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift
    #13 0xffff9db584c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #14 0xffff9db58594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #15 0xaaaabf4ec32c in _start (/src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.xctest+0x5c32c) (BuildId: 835d26df23c8894a9125db6195006ce0aee2d284)

Indirect leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0xaaaabf578560 in malloc /home/build-user/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0xffff9f65329c in swift_slowAlloc (/usr/lib/swift/linux/libswiftCore.so+0x3f329c) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #2 0xffff9f6536b8 in swift_allocObject (/usr/lib/swift/linux/libswiftCore.so+0x3f36b8) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #3 0xffff9f3bbeb4 in $ss22_ContiguousArrayBufferV20_consumeAndCreateNew14bufferIsUnique15minimumCapacity13growForAppendAByxGSb_SiSbtFSS5IndexV_Tg5Tm Swift.o
    #4 0xffff9f4ffe14 in $sSa034_makeUniqueAndReserveCapacityIfNotB0yyFyXl_Ts5 (/usr/lib/swift/linux/libswiftCore.so+0x29fe14) (BuildId: 20ba6bf673eefe7dbaa48fe92b80636e7d10d7fc)
    #5 0xffff9de34aec in $s6XCTest11XCTMainMisc_9arguments9observersAA19TestSuiteOrExitCodeOSayAA0A4CaseCm04testK5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF crtstuff.c
    #6 0xffff9de36fa0 in $s6XCTest7XCTMain_9arguments9observerss5Int32VSayAA0A4CaseCm04testF5Class_SaySS_yAHKctG8allTeststG_SaySSGSayAA0A11Observation_pGSgtF (/usr/lib/swift/linux/libXCTest.so+0x26fa0) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #7 0xffff9de37130 in $s6XCTest7XCTMainys5NeverOSayAA0A4CaseCm04testD5Class_SaySS_yAFKctG8allTeststGF (/usr/lib/swift/linux/libXCTest.so+0x27130) (BuildId: 0247c17b45dc5c03a92075e2ba612195d9a12d2a)
    #8 0xaaaabf5ff7d4 in $s23TempExamplePackageTests6RunnerV4mainyyFZ /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift:543:14
    #9 0xaaaabf5ff84c in $s23TempExamplePackageTests6RunnerV5$mainyyFZ /<compiler-generated>
    #10 0xaaaabf5ff864 in main /src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.derived/runner.swift
    #11 0xffff9db584c0  (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #12 0xffff9db58594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: d6c205bda1b6e91815f8fef45bdf56bc2239c37e)
    #13 0xaaaabf4ec32c in _start (/src/.build/aarch64-unknown-linux-gnu/debug/TempExamplePackageTests.xctest+0x5c32c) (BuildId: 835d26df23c8894a9125db6195006ce0aee2d284)

SUMMARY: AddressSanitizer: 368 byte(s) leaked in 6 allocation(s).
◇ Test run started.
↳ Testing Library Version: 6.2.1 (c9d57c83568b06d)
↳ Target Platform: aarch64-unknown-linux-gnu
◇ Test example() started.
✔ Test example() passed after 0.001 seconds.
✔ Test run with 1 test in 0 suites passed after 0.001 seconds.

If you disable XCTests, the leak error report goes away.
A similar error is reported with Swift:6.1 and Swift:6.0 release images. (adjusting the Swift tools version down to 6.0 to enable the checks)

  • container run -it -c 4 -m 8g -v "$(pwd):/src" -w src/ swift:6.1 swift test --sanitize=address
  • container run -it -c 4 -m 8g -v "$(pwd):/src" -w src/ swift:6.0 swift test --sanitize=address
    and on the latest nightly main branch build:
  • container run -it -c 4 -m 8g -v "$(pwd):/src" -w src/ swiftlang/swift:nightly swift test --sanitize=address

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions