From 7d1f464b2504591b47445053f234be4196e525dd Mon Sep 17 00:00:00 2001 From: Dario Rexin Date: Fri, 23 Jul 2021 10:34:50 -0700 Subject: [PATCH] Fix memory leak in PropertyListSerialization rdar://80919378 --- Sources/Foundation/PropertyListSerialization.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Foundation/PropertyListSerialization.swift b/Sources/Foundation/PropertyListSerialization.swift index 7677ba5462..8a70bf8a5f 100644 --- a/Sources/Foundation/PropertyListSerialization.swift +++ b/Sources/Foundation/PropertyListSerialization.swift @@ -61,9 +61,9 @@ open class PropertyListSerialization : NSObject { open class func propertyList(from data: Data, options opt: ReadOptions = [], format: UnsafeMutablePointer?) throws -> Any { var fmt = kCFPropertyListBinaryFormat_v1_0 var error: Unmanaged? = nil - let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer) -> NSObject? in - withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer?>) -> NSObject? in - return unsafeBitCast(CFPropertyListCreateWithData(kCFAllocatorSystemDefault, data._cfObject, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr), to: NSObject.self) + let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer) -> AnyObject? in + withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer?>) -> AnyObject? in + return CFPropertyListCreateWithData(kCFAllocatorSystemDefault, data._cfObject, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr).takeRetainedValue() } } format?.pointee = PropertyListFormat(rawValue: UInt(fmt.rawValue))! @@ -77,9 +77,9 @@ open class PropertyListSerialization : NSObject { internal class func propertyList(with stream: CFReadStream, options opt: ReadOptions, format: UnsafeMutablePointer ?) throws -> Any { var fmt = kCFPropertyListBinaryFormat_v1_0 var error: Unmanaged? = nil - let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer) -> NSObject? in - withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer?>) -> NSObject? in - return unsafeBitCast(CFPropertyListCreateWithStream(kCFAllocatorSystemDefault, stream, 0, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr), to: NSObject.self) + let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer) -> AnyObject? in + withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer?>) -> AnyObject? in + return CFPropertyListCreateWithStream(kCFAllocatorSystemDefault, stream, 0, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr).takeRetainedValue() } } format?.pointee = PropertyListFormat(rawValue: UInt(fmt.rawValue))!