Skip to content

Commit e35f936

Browse files
committed
getpwnam_r returns the result by filling in the memory of the pointer to the struct passwd
ASAN failure caught double free else wise.
1 parent 4b290f8 commit e35f936

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Foundation/NSPathUtilities.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,12 @@ public func NSHomeDirectoryForUser(user: String?) -> String? {
524524
var info = passwd()
525525
let bufSize = Int(BUFSIZ * 10)
526526
var buffer = [Int8](count: bufSize, repeatedValue: 0)
527-
var result = UnsafeMutablePointer<passwd>.alloc(1)
527+
var result: UnsafeMutablePointer<passwd> = nil
528528

529529
var homeDir: String? = nil
530530
if getpwnam_r(usr, &info, &buffer, bufSize, &result) == 0 && info.pw_dir != nil {
531531
homeDir = String.fromCString(info.pw_dir)
532532
}
533-
534-
result.dealloc(1)
535533

536534
return homeDir
537535
}

0 commit comments

Comments
 (0)