Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6449] FileManager.removeItem(atPath) leaks #4050

Closed
swift-ci opened this issue Nov 21, 2017 · 2 comments
Closed

[SR-6449] FileManager.removeItem(atPath) leaks #4050

swift-ci opened this issue Nov 21, 2017 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-6449
Radar None
Original Reporter oc243 (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Leak
Assignee @spevans
Priority Medium

md5: ed00226ba5251454be00fae148b361f3

Issue Description:

FileManager.removeItem(atPath: ) leaks when removing a non-empty directory, as shown in this repro:

func removeItem() throws -> () {
    let fm = FileManager()
    while true {
        let _ = try fm.createDirectory(atPath: "/tmp/foo", withIntermediateDirectories: true, attributes: [:])
        let _ = fm.createFile(atPath: "/tmp/foo/bar", contents: nil)
        try fm.removeItem(atPath: "/tmp/foo/")
    }
}

Looks like the issue is that Foundation.FileManager.fileSystemRepresentation returns a C-string that is not free'd in the caller (and can't be free'd by an autorelease pool on Linux).

@swift-ci
Copy link
Contributor Author

Comment by Oliver Chick (JIRA)

Valgrind says:

==29889== 948,658 bytes in 11,569 blocks are definitely lost in loss record 64 of 64
==29889== at 0x4C2DBF6: malloc (vg_replace_malloc.c:299)
==29889== by 0x52EAD75: swift_slowAlloc (in /home/oliver/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2017-11-16-a/usr/lib/swift/linux/libswiftCore.so)
==29889== by 0x58711E3: function signature specialization <Arg[0] = Owned To Guaranteed and Exploded, Arg[1] = Dead> of Foundation.FileManager.fileSystemRepresentation(withPath: Swift.String) -> Swift.UnsafePointer<Swift.Int8> (in /home/oliver/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2017-11-16-a/usr/lib/swift/linux/libFoundation.so)
==29889== by 0x58778A2: function signature specialization <Arg[0] = Exploded, Arg[1] = Dead> of Foundation.FileManager.removeItem(atPath: Swift.String) throws -> () (in /home/oliver/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2017-11-16-a/usr/lib/swift/linux/libFoundation.so)
==29889== by 0x586B058: Foundation.FileManager.removeItem(atPath: Swift.String) throws -> () (in /home/oliver/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2017-11-16-a/usr/lib/swift/linux/libFoundation.so)
==29889== by 0x109CAD: main.removeItem() throws -> () (in /home/oliver/main)
==29889== by 0x109A30: main (in /home/oliver/main)

@spevans
Copy link
Collaborator

spevans commented Feb 19, 2018

#1397

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants