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-462] NSFIleManager.fileSystemRepresentationWithPath leaks memory #4471

Closed
swift-ci opened this issue Jan 4, 2016 · 1 comment
Closed

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jan 4, 2016

Previous ID SR-462
Radar None
Original Reporter Eugene Gubin (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, CoreFoundation
Assignee None
Priority Medium

md5: 15808bd575cde83e771a99499ba11747

Issue Description:

Code to reproduce:

let fm = NSFileManager.defaultManager()
for _ in 0..<1_000_000 {
    let path = "/Users/Hemet/Library"
    let fsr = fm.fileSystemRepresentationWithPath(path)
}

Debugger reports 140 MB allocated.

public func fileSystemRepresentationWithPath(path: String) -> UnsafePointer<Int8> {
        precondition(path != "", "Empty path argument")
        let len = CFStringGetMaximumSizeOfFileSystemRepresentation(path._cfObject)
        if len == kCFNotFound {
            return nil
        }
        // memory allocated here
        let buf = UnsafeMutablePointer<Int8>.alloc(len)
        for i in 0..<len {
            buf.advancedBy(i).initialize(0)
        }
        if !path._nsObject.getFileSystemRepresentation(buf, maxLength: len) {
            buf.destroy(len)
            buf.dealloc(len)
            return nil
        }
        // never freed, leak here
        return UnsafePointer(buf)
    }
@swift-ci
Copy link
Contributor Author

swift-ci commented Jan 4, 2016

Comment by Eugene Gubin (JIRA)

It is known issue https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Issues.md (see last paragraph)

@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

1 participant