调用 SecTrustCreateWithCertificates 会导致 Alamofire 内存泄漏吗?
Will the call to SecTrustCreateWithCertificates cause a memory leak in Alamofire?
在 Alamofire,
extension AlamofireExtension where ExtendedType == SecCertificate {
public var publicKey: SecKey? {
let policy = SecPolicyCreateBasicX509()
var trust: SecTrust?
let trustCreationStatus = SecTrustCreateWithCertificates(type, policy, &trust)
guard let createdTrust = trust, trustCreationStatus == errSecSuccess else { return nil }
return SecTrustCopyPublicKey(createdTrust)
}
}
SecTrustCreateWithCertificates 调用创建一个信任对象。根据苹果官方文档:
trust
On return, points to the newly created trust management object.
Call the CFRelease function to release this object when you are
finished with it.
信任对象应该通过调用CFRelease函数来释放(像这样:CFRelease(createdTrust)
),但是这里没有调用。
会不会有内存泄漏?
CoreFoundation 对象在从 Swift 使用时自动进行内存管理。
在 Alamofire,
extension AlamofireExtension where ExtendedType == SecCertificate {
public var publicKey: SecKey? {
let policy = SecPolicyCreateBasicX509()
var trust: SecTrust?
let trustCreationStatus = SecTrustCreateWithCertificates(type, policy, &trust)
guard let createdTrust = trust, trustCreationStatus == errSecSuccess else { return nil }
return SecTrustCopyPublicKey(createdTrust)
}
}
SecTrustCreateWithCertificates 调用创建一个信任对象。根据苹果官方文档:
trust On return, points to the newly created trust management object. Call the CFRelease function to release this object when you are finished with it.
信任对象应该通过调用CFRelease函数来释放(像这样:CFRelease(createdTrust)
),但是这里没有调用。
会不会有内存泄漏?
CoreFoundation 对象在从 Swift 使用时自动进行内存管理。