Skip to content

Commit 8efa652

Browse files
committed
Foundation: fix invalid free
The memory in the `String` is not-being copied, and thus is more of a view into the memory, not an owning reference. Do not free this memory after the destruction of the object.
1 parent 6167997 commit 8efa652

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Foundation/NSData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
602602
let buffer = UnsafeMutableRawBufferPointer(start: ptr, count: capacity)
603603
let length = NSData.base64EncodeBytes(self, options: options, buffer: buffer)
604604

605-
return String(bytesNoCopy: ptr, length: length, encoding: .ascii, freeWhenDone: true)!
605+
return String(bytesNoCopy: ptr, length: length, encoding: .ascii, freeWhenDone: false)!
606606
}
607607

608608
/// Creates a Base64, UTF-8 encoded Data from the data object using the given options.

0 commit comments

Comments
 (0)