최근 거대한 라이브러리를 ARC로 마이그레이션했으며 도구가 필요없는 섹션에서 두통이 발생했습니다. 여기에 코드입니다 : 이것은 꽤 똑바로 앞으로, 그러나, passwordData 객체가 overreleased되고있다한다Toll-Bridge overrelease
+ (NSString *)getKeychainItem:(NSString *)identifier
{
NSString *fullIdentifier = [NSString stringWithFormat:@"%@%@", kIdentifierPrefix, identifier];
NSMutableDictionary *queryKeychain;
OSStatus status = noErr;
queryKeychain = [NSMutableDictionary dictionary];
// Set the public key query dictionary.
[queryKeychain setObject:(__bridge id)kSecClassGenericPassword
forKey:(__bridge id)kSecClass];
// Get the key.
CFDataRef data;
CFDictionaryRef queryKeychainCF = (__bridge CFDictionaryRef)queryKeychain;
status = SecItemCopyMatching(queryKeychainCF, (CFTypeRef *)&data);
NSData *passwordData = (__bridge_transfer NSData *)data;
NSString *password;
if (status == noErr)
{
password = [[NSString alloc] initWithBytes:[passwordData bytes]
length:[passwordData length]
encoding:NSUTF8StringEncoding];
}
else if (status != errSecItemNotFound)
{
NSLog(@"Error getting keychain item %@ -- OSStatus: %lu", identifier, status);
}
return password;
}
내가 스택 추적이 this 왜, 아무 생각이 없습니다. passwordData
을 nil
으로 설정하고 __bridge__transfer
을 수행하지 않으면 충돌이 발생하지 않습니다. 왜 어떤 아이디어?
고맙습니다.
'CFBridgingRelease'도 실패하는 것 같습니다 : http://i.imgur.com/8Wi4gB7.png.'SecItemCopyMatching'이 냄새를 맡았다 고 생각하기 시작했습니다. –
정기적 인'__bridge'을하고 NSLog (@ "% d", CFGetRetainCount (data))를 여러 위치에 두어보십시오. NSString 메모리의 소유권을 가정 수 있습니다. – Luke
감사합니다 루크,하지만 문제는 또 하나, SecItemCopyMatching 동작과 관련이 있습니다. –