Skip to content

Commit 4eac74e

Browse files
authored
Merge pull request #906 from nethraravindran/nsuuid-branch
2 parents 33311e5 + 9bf18e9 commit 4eac74e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Foundation/NSUUID.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ import CoreFoundation
1818

1919
open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
2020
internal var buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 16)
21+
22+
deinit {
23+
buffer.deinitialize()
24+
buffer.deallocate(capacity: 16)
25+
}
2126

2227
public override init() {
2328
_cf_uuid_generate_random(buffer)
2429
}
2530

2631
public convenience init?(uuidString string: String) {
2732
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 16)
33+
defer {
34+
buffer.deinitialize()
35+
buffer.deallocate(capacity: 16)
36+
}
2837
if _cf_uuid_parse(string, buffer) != 0 {
2938
return nil
3039
}
@@ -41,6 +50,10 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
4150

4251
open var uuidString: String {
4352
let strPtr = UnsafeMutablePointer<Int8>.allocate(capacity: 37)
53+
defer {
54+
strPtr.deinitialize()
55+
strPtr.deallocate(capacity: 37)
56+
}
4457
_cf_uuid_unparse_upper(buffer, strPtr)
4558
return String(cString: strPtr)
4659
}
@@ -69,6 +82,10 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
6982
guard let data = decodedData else { return nil }
7083
guard data.count == 16 else { return nil }
7184
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 16)
85+
defer {
86+
buffer.deinitialize()
87+
buffer.deallocate(capacity: 16)
88+
}
7289
data.copyBytes(to: buffer, count: 16)
7390
self.init(uuidBytes: buffer)
7491
}

0 commit comments

Comments
 (0)