How to debug a memory leak that takes place in Ubuntu only?

Hi.

When I run my NIO based app test suite on a Mac, everything is OK. However, when the same test suite is run on Ubuntu, I get a memory leak error. How am I to debug this? I don't have much experience with memory leaks, and I cannot figure out where the leak takes place. Here is the snippet from my GitHub Action log:

Test Suite 'All tests' passed at 2023-07-31 14:47:54.970
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.003 (0.003) seconds
=================================================================
==4162==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x55753bc461e7  (/home/runner/work/SipOne/SipOne/.build/x86_64-unknown-linux-gnu/release/SipOnePackageTests.xctest+0x17d1e7)
    #1 0x7f7bf9029dc2  (/opt/hostedtoolcache/swift-Ubuntu/5.8/x64/usr/bin/../lib/swift/linux/libswiftCore.so+0x3ebdc2)
    #2 0x7f7bf9505c88  (/opt/hostedtoolcache/swift-Ubuntu/5.8/x64/usr/bin/../lib/swift/linux/libXCTest.so+0x3ec88) (BuildId: bebcb3079551228b8529ae2ddccce28a3d8babbd)
SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
Error: Process completed with exit code 1.

Here is the command that triggers the test (taken from Swift.org - Testing):

swift test --sanitize=address -c release -Xswiftc -enable-testing

Any recommendations?

Thanks.

swift.org has guides for doing this

I read this, but I am truly confused how to apply the contents of this article to the unit testing. Anything simple, perhaps?

If I build the test target, then will I be able to run it like an executable target without using the test command?

Using addr2line -e {filename} -a {address} -ipf | swift demangle, I am getting the following lines but I struggle to make sense of them. I picked few at random out of 22 shown.

addr2line: DWARF error: invalid or unhandled FORM value: 0x23
0x000000000017cef8: posix_memalign at ??:?
0x00000000003c3364: swift_slowAlloc at ??:?
0x0000000000045890: XCTest.XCTWaiter.wait(for: [XCTest.XCTestExpectation], timeout: Swift.Double, enforceOrder: Swift.Bool, file: Swift.StaticString, line: Swift.Int) -> XCTest.XCTWaiter.Result at ??:?
0x00000000000273f8: __libc_init_first at ??:?

And the 'heaptrack --analyze' returns nothing:

finished reading file, now analyzing data:

MOST CALLS TO ALLOCATION FUNCTIONS

PEAK MEMORY CONSUMERS

MOST TEMPORARY ALLOCATIONS

total runtime: 0.015000s.
calls to allocation functions: 0 (0/s)
temporary memory allocations: 0 (0/s)
peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 43.75M
total memory leaked: 0B

Can you point me in the right direction?

That looks like a leak in XCTest - I'd raise an issue on GH, but beyond that there's not a huge amount that can be done I'm afraid

1 Like