Skip to content

[SR-12551] [lsan] Leaks detected in corelibs-foundation URL init and Process.run() #3260

Open
@benlangmuir

Description

@benlangmuir
Previous ID SR-12551
Radar rdar://problem/62202306
Original Reporter @benlangmuir
Type Bug
Environment

swift-DEVELOPMENT-SNAPSHOT-2020-04-06-a (nightly-bionic docker)

Additional Detail from JIRA
Votes 0
Component/s Compiler, Foundation
Labels Bug
Assignee None
Priority Medium

md5: aa4a32a4abe06a4e5b00ab8067024f9b

Issue Description:

When I try to test indexstore-db[0] with -sanitize=address on Linux, LeakSanitizer reports issues in Foundation code.

[0] https://github.com/apple/indexstore-db

Leak 1: URL(fileURLWithPath🙂

 ==2080==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
 #​0 0x562896ed770d in malloc _asan_rtl_
 #​1 0x7f941ec7f821 in swift_slowAlloc ??:?
 #​2 0x562897028c74 in globalinit_33_B8921876E18C3584C528F0F839697E3C_func0 /home/docker_user/src/lsp/indexstore-db/Tests/IndexStoreDBTests/LocationScannerTests.swift:19
 #​3 0x7f941e66b826 in __pthread_once_slow ??:?

This code is just:

final class LocationScannerTests: XCTestCase {
  static let magicURL: URL = URL(fileURLWithPath: "/magic.swift")

Leak 2: Process.run()

 ==1939==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
 #​0 0x557471fce70d in malloc _asan_rtl_
 #​1 0x7f992113d297 in operator new(unsigned long) ??:?
 #​2 0x557472041bed in static (extension in ISDBTibs):Foundation.Process.tibs_checkNonZeroExit(arguments: [Swift.String], environment: [Swift.String : Swift.String]?) throws -> Swift.String /home/docker_user/src/lsp/indexstore-db/Sources/ISDBTibs/Process.swift:43
 #​3 0x55747208814b in ISDBTibs.findTool(name: Swift.String) -> Foundation.URL? /home/docker_user/src/lsp/indexstore-db/Sources/ISDBTibs/TibsToolchain.swift:213
 #​4 0x557472085a9c in static ISDBTibs.TibsToolchain.testDefault.getter : ISDBTibs.TibsToolchain /home/docker_user/src/lsp/indexstore-db/Sources/ISDBTibs/TibsToolchain.swift:177
 #​5 0x55747201f16d in (extension in ISDBTestSupport):XCTest.XCTestCase.mutableTibsTestWorkspace(name: Swift.String, testFile: Swift.String) throws -> ISDBTestSupport.TibsTestWorkspace? /home/docker_user/src/lsp/indexstore-db/Sources/ISDBTestSupport/TibsTestWorkspace.swift:240
 #​6 0x557472110d66 in IndexStoreDBTests.IndexTests.testEditsSimple() throws -> () /home/docker_user/src/lsp/indexstore-db/Tests/IndexStoreDBTests/IndexTests.swift:145
 #​7 0x557472135418 in implicit closure #​8 () throws -> () in implicit closure #​7 (IndexStoreDBTests.IndexTests) -> () throws -> () in variable initialization expression of static IndexStoreDBTests.IndexTests.__allTests__IndexTests : [(Swift.String, (IndexStoreDBTests.IndexTests) -> () throws -> ())] /home/docker_user/src/lsp/indexstore-db/Tests/IndexStoreDBTests/XCTestManifests.swift:22
 #​8 0x557472139aee in partial apply forwarder for implicit closure #​8 () throws -> () in implicit closure #​7 (IndexStoreDBTests.IndexTests) -> () throws -> () in variable initialization expression of static IndexStoreDBTests.IndexTests.__allTests__IndexTests : [(Swift.String, (IndexStoreDBTests.IndexTests) -> () throws -> ())] XCTestManifests.swift.o:?
 #​9 0x5574720d9a8e in reabstraction thunk helper from @escaping @callee_guaranteed () -> (@error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error) crtstuff.c:?
 #​10 0x557472139b83 in reabstraction thunk helper from @escaping @callee_guaranteed () -> (@error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error)partial apply forwarder with unmangled suffix ".70" XCTestManifests.swift.o:?
 #​11 0x7f99231aae60 in partial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed () -> (@out (), @error @owned Swift.Error) to @escaping @callee_guaranteed () -> (@error @owned Swift.Error) XCTestCase.swift.o:?
 #&#8203;12 0x7f99231aac6b in partial apply forwarder for closure #&#8203;1 (XCTest.XCTestCase) throws -> () in XCTest.(test in _3BE257A46ADB477C7BF2D39968B39F9D)<A where A: XCTest.XCTestCase>((A) -> () throws -> ()) -> (XCTest.XCTestCase) throws -> () XCTestCase.swift.o:?
 #&#8203;13 0x7f99231aabe3 in partial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed (@guaranteed XCTest.XCTestCase) -> (@error @owned Swift.Error) to @escaping @callee_guaranteed (@in_guaranteed XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) XCTestCase.swift.o:?
 #&#8203;14 0x7f99231aaf38 in reabstraction thunk helper from @escaping @callee_guaranteed (@guaranteed XCTest.XCTestCase) -> (@error @owned Swift.Error) to @escaping @callee_guaranteed (@in_guaranteed XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error)partial apply forwarder with unmangled suffix ".19" XCTestCase.swift.o:?
 #&#8203;15 0x7f992319b846 in partial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed (@in_guaranteed XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) to @escaping @callee_guaranteed (@guaranteed XCTest.XCTestCase) -> (@error @owned Swift.Error) XCTestCaseSuite.swift.o:?
 #&#8203;16 0x7f99231a9596 in XCTest.XCTestCase.invokeTest() -> () ??:?
 #&#8203;17 0x7f99231a92d5 in XCTest.XCTestCase.perform(XCTest.XCTestRun) -> () ??:?
 #&#8203;18 0x7f99231acf55 in XCTest.XCTest.run() -> () ??:?
 #&#8203;19 0x7f99231ab1ef in XCTest.XCTestSuite.perform(XCTest.XCTestRun) -> () ??:?
 #&#8203;20 0x7f99231acf55 in XCTest.XCTest.run() -> () ??:?
 #&#8203;21 0x7f99231ab1ef in XCTest.XCTestSuite.perform(XCTest.XCTestRun) -> () ??:?
 #&#8203;22 0x7f99231acf55 in XCTest.XCTest.run() -> () ??:?
 #&#8203;23 0x7f99231a7d49 in XCTest.XCTMain(_: [(testCaseClass: XCTest.XCTestCase.Type, allTests: [(Swift.String, (XCTest.XCTestCase) throws -> ())])], arguments: [Swift.String]) -> Swift.Never ??:?
 #&#8203;24 0x7f99231a7778 in XCTest.XCTMain([(testCaseClass: XCTest.XCTestCase.Type, allTests: [(Swift.String, (XCTest.XCTestCase) throws -> ())])]) -> Swift.Never ??:?
 #&#8203;25 0x557472104bbe in main /home/docker_user/src/lsp/indexstore-db/Tests/LinuxMain.swift:10
 #&#8203;26 0x7f99208bab96 in __libc_start_main ??:?

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).

This leak is reported on the call to "run":

 let p = Process()
 let out = Pipe()

if #available(macOS 10.13, *)

{ p.executableURL = URL(fileURLWithPath: arguments[0], isDirectory: false) }

else

{ p.launchPath = arguments[0] }

p.arguments = Array(arguments[1...])
 if let environment = environment

{ p.environment = environment }

p.standardOutput = out

if #available(macOS 10.13, *)

{ try p.run() }

else

{ p.launch() }

Reproducing

To reproduce for sure:

1. On Linux, use nightly-bionic docker image
2. apt-get install ninja-build
3. git clone https://github.com/apple/indexstore-db.git
4. cd indexstore-db
5. swift test -Xcxx -I/usr/lib/swift -Xcc -I/usr/lib/swift/Block --sanitize=address

I tried reducing: This reproduces a leak with URL, but I'm not 100% certain if it's the same leak.

 (docker) $ cat t.swift 
 import Foundation
 let url: URL = URL(fileURLWithPath: "/magic.swift")
 print(url)

(docker) $ swiftc -sanitize=address t.swift -o t -g

(docker) $ ./t | ../../s/llvm-project/compiler-rt/lib/asan/scripts/asan_symbolize.py -d

=================================================================
 ==2135==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
 #&#8203;0 0x5651629714bd (/home/docker_user/src/lsp/indexstore-db/t+0x964bd)
 #&#8203;1 0x7f4684d87821 (/usr/lib/swift/linux/libswiftCore.so+0x404821)
 #&#8203;2 0x5651629a12e5 (/home/docker_user/src/lsp/indexstore-db/t+0xc62e5)
 #&#8203;3 0x7f468336cb96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 208 byte(s) in 1 object(s) allocated from:
 #&#8203;0 0x5651629714bd (/home/docker_user/src/lsp/indexstore-db/t+0x964bd)
 #&#8203;1 0x7f4684d87821 (/usr/lib/swift/linux/libswiftCore.so+0x404821)
 #&#8203;2 0x7f46853dc156 (/usr/lib/swift/linux/libFoundation.so+0x4d8156)
 #&#8203;3 0x5651629a12e5 (/home/docker_user/src/lsp/indexstore-db/t+0xc62e5)
 #&#8203;4 0x7f468336cb96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 72 byte(s) in 1 object(s) allocated from:
 #&#8203;0 0x565162971f57 (/home/docker_user/src/lsp/indexstore-db/t+0x96f57)
 #&#8203;1 0x7f4684d87844 (/usr/lib/swift/linux/libswiftCore.so+0x404844)

SUMMARY: AddressSanitizer: 304 byte(s) leaked in 3 allocation(s).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions