@@ -18,13 +18,22 @@ import CoreFoundation
18
18
19
19
open class NSUUID : NSObject , NSCopying , NSSecureCoding , NSCoding {
20
20
internal var buffer = UnsafeMutablePointer< UInt8> . allocate( capacity: 16 )
21
+
22
+ deinit {
23
+ buffer. deinitialize ( )
24
+ buffer. deallocate ( capacity: 16 )
25
+ }
21
26
22
27
public override init ( ) {
23
28
_cf_uuid_generate_random ( buffer)
24
29
}
25
30
26
31
public convenience init ? ( uuidString string: String ) {
27
32
let buffer = UnsafeMutablePointer< UInt8> . allocate( capacity: 16 )
33
+ defer {
34
+ buffer. deinitialize ( )
35
+ buffer. deallocate ( capacity: 16 )
36
+ }
28
37
if _cf_uuid_parse ( string, buffer) != 0 {
29
38
return nil
30
39
}
@@ -41,6 +50,10 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
41
50
42
51
open var uuidString : String {
43
52
let strPtr = UnsafeMutablePointer< Int8> . allocate( capacity: 37 )
53
+ defer {
54
+ strPtr. deinitialize ( )
55
+ strPtr. deallocate ( capacity: 37 )
56
+ }
44
57
_cf_uuid_unparse_upper ( buffer, strPtr)
45
58
return String ( cString: strPtr)
46
59
}
@@ -69,6 +82,10 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
69
82
guard let data = decodedData else { return nil }
70
83
guard data. count == 16 else { return nil }
71
84
let buffer = UnsafeMutablePointer< UInt8> . allocate( capacity: 16 )
85
+ defer {
86
+ buffer. deinitialize ( )
87
+ buffer. deallocate ( capacity: 16 )
88
+ }
72
89
data. copyBytes ( to: buffer, count: 16 )
73
90
self . init ( uuidBytes: buffer)
74
91
}
0 commit comments