Skip to content

Commit 2ff9184

Browse files
committed
Fix memory corruption with NSMutableData(length:)
1 parent 73218c8 commit 2ff9184

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Foundation/NSData.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,7 @@ extension NSMutableData {
936936
}
937937

938938
public convenience init?(length: Int) {
939-
let memory = malloc(length)
940-
self.init(bytes: memory, length: length, copy: false) { buffer, amount in
941-
free(buffer)
942-
}
939+
self.init(bytes: nil, length: 0)
940+
self.length = length
943941
}
944942
}

0 commit comments

Comments
 (0)