Skip to content

Commit d72a6b5

Browse files
committed
SR-6449: FileManager.removeItem(atPath) leaks
- FileManager.fileSystemRepresentation returns a heap allocated pointer that needs to be freed by the caller.
1 parent 359c396 commit d72a6b5

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

Foundation/FileManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ open class FileManager : NSObject {
461461
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
462462
ps.deinitialize(count: 2)
463463
ps.deallocate()
464+
fsRep.deallocate()
464465

465466
if stream != nil {
466467
defer {
@@ -1037,6 +1038,7 @@ extension FileManager {
10371038
_stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
10381039
ps.deinitialize(count: 2)
10391040
ps.deallocate()
1041+
fsRep.deallocate()
10401042
} else {
10411043
_rootError = _NSErrorWithErrno(ENOENT, reading: true, url: url)
10421044
}

TestFoundation/TestFileManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class TestFileManager : XCTestCase {
140140
XCTAssertEqual(UInt8(bitPattern: result[0]), 0xE2)
141141
XCTAssertEqual(UInt8(bitPattern: result[1]), 0x98)
142142
XCTAssertEqual(UInt8(bitPattern: result[2]), 0x83)
143+
result.deallocate()
143144
}
144145

145146
func test_fileAttributes() {

0 commit comments

Comments
 (0)