Skip to content

Commit 023ceb7

Browse files
committed
Fixed memory leaks
1 parent 15ba4cd commit 023ceb7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ColorSetKit/ColorSetStream.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ public class ColorSetStream: NSObject
242242
{
243243
let nb = UnsafeMutableBufferPointer< UInt64 >.allocate( capacity: 1 )
244244

245+
defer
246+
{
247+
nb.deallocate()
248+
}
249+
245250
if self.read( size: 8, in: nb )
246251
{
247252
guard let n = nb.first?.littleEndian
@@ -290,6 +295,14 @@ public class ColorSetStream: NSObject
290295
let bb = UnsafeMutableBufferPointer< Double >.allocate( capacity: 1 )
291296
let ab = UnsafeMutableBufferPointer< Double >.allocate( capacity: 1 )
292297

298+
defer
299+
{
300+
rb.deallocate()
301+
gb.deallocate()
302+
bb.deallocate()
303+
ab.deallocate()
304+
}
305+
293306
if self.read( size: 8, in: rb ),
294307
self.read( size: 8, in: gb ),
295308
self.read( size: 8, in: bb ),
@@ -325,6 +338,11 @@ public class ColorSetStream: NSObject
325338
{
326339
let buffer = UnsafeMutableBufferPointer< UInt8 >.allocate( capacity: Int( length ) )
327340

341+
defer
342+
{
343+
buffer.deallocate()
344+
}
345+
328346
if self.read( size: length, in: buffer )
329347
{
330348
return Data( buffer: buffer )

0 commit comments

Comments
 (0)