Skip to content

Commit c9281b7

Browse files
authored
Merge pull request #3017 from drexin/wip-cp-6cd941
[5.5] Fix memory leak in PropertyListSerialization
2 parents f06c219 + 7d1f464 commit c9281b7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Sources/Foundation/PropertyListSerialization.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ open class PropertyListSerialization : NSObject {
6161
open class func propertyList(from data: Data, options opt: ReadOptions = [], format: UnsafeMutablePointer<PropertyListFormat>?) throws -> Any {
6262
var fmt = kCFPropertyListBinaryFormat_v1_0
6363
var error: Unmanaged<CFError>? = nil
64-
let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>) -> NSObject? in
65-
withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer<Unmanaged<CFError>?>) -> NSObject? in
66-
return unsafeBitCast(CFPropertyListCreateWithData(kCFAllocatorSystemDefault, data._cfObject, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr), to: NSObject.self)
64+
let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>) -> AnyObject? in
65+
withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer<Unmanaged<CFError>?>) -> AnyObject? in
66+
return CFPropertyListCreateWithData(kCFAllocatorSystemDefault, data._cfObject, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr).takeRetainedValue()
6767
}
6868
}
6969
format?.pointee = PropertyListFormat(rawValue: UInt(fmt.rawValue))!
@@ -77,9 +77,9 @@ open class PropertyListSerialization : NSObject {
7777
internal class func propertyList(with stream: CFReadStream, options opt: ReadOptions, format: UnsafeMutablePointer <PropertyListFormat>?) throws -> Any {
7878
var fmt = kCFPropertyListBinaryFormat_v1_0
7979
var error: Unmanaged<CFError>? = nil
80-
let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>) -> NSObject? in
81-
withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer<Unmanaged<CFError>?>) -> NSObject? in
82-
return unsafeBitCast(CFPropertyListCreateWithStream(kCFAllocatorSystemDefault, stream, 0, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr), to: NSObject.self)
80+
let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>) -> AnyObject? in
81+
withUnsafeMutablePointer(to: &error) { (outErr: UnsafeMutablePointer<Unmanaged<CFError>?>) -> AnyObject? in
82+
return CFPropertyListCreateWithStream(kCFAllocatorSystemDefault, stream, 0, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr).takeRetainedValue()
8383
}
8484
}
8585
format?.pointee = PropertyListFormat(rawValue: UInt(fmt.rawValue))!

0 commit comments

Comments
 (0)