Ios SecPKCS12Import内存泄漏
我的应用程序使用相互身份验证连接到我的服务器,因此我有一个包含证书的.p12文件。一切都按预期的方式运行,但当我使用仪器评测我的应用程序时,它会在以下线路上检测到内存泄漏:Ios SecPKCS12Import内存泄漏,ios,memory-leaks,ssl,Ios,Memory Leaks,Ssl,我的应用程序使用相互身份验证连接到我的服务器,因此我有一个包含证书的.p12文件。一切都按预期的方式运行,但当我使用仪器评测我的应用程序时,它会在以下线路上检测到内存泄漏: if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]){ NSData* p12data = [NSData dataWithContentsOfF
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]){
NSData* p12data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"client" ofType:@"p12"]];
CFArrayRef itemsCFArray = nil;
NSDictionary* dico = [NSDictionary dictionaryWithObjectsAndKeys:@"password",kSecImportExportPassphrase, nil];
// MEMORY LEAK just below
OSStatus check = SecPKCS12Import((__bridge CFDataRef)p12data, (__bridge CFDictionaryRef)dico, &itemsCFArray);
if(check != noErr){
NSLog(@"Error importing PKCS");
}
NSArray* items = (__bridge NSArray*)itemsCFArray;
SecIdentityRef identityRef = (__bridge SecIdentityRef)[[items objectAtIndex:0] objectForKey:(__bridge id)kSecImportItemIdentity];
NSURLCredential* credential = [NSURLCredential credentialWithIdentity:identityRef certificates:nil persistence:NSURLCredentialPersistenceNone];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
我尝试改用CFDictionaryRef,但它无法解决错误
我发现有人有同样的问题,但他的解决方案是ios4,我正在使用ios5(实际上,我已经在做同样的事情):(法语,对不起)
我如何解决这个问题?苹果会因为内存泄漏而拒绝我的应用程序吗?我认为问题不在于词典,似乎泄漏的是ItemsFarray。SecPKCS12Import将CF引用传回ItemsFarray,当您使用其中的对象时,需要将其释放
创建凭证后,请尝试调用CFRelease(itemsCFArray)。正如我在帖子中所说,他正在使用ios4,而我正在使用ios5。我的代码与他的解决方案类似,具有ios5的细节。