Question: I'm using the KeyChainItemWrapper from Apple's sample code to store user password for authentication, but when I call it to set the password:

```
   [keychain setObject:passwordField.text forKey:(id)kSecValueData];

```

It dribbles memory leaks all over my shirt. The problem apparently traces back to line 274 in KeyChainItemWrapper.m, which is this: 

```
if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes) == noErr)
{

```

How would I fix this, and should I be more careful when working with Apple sample code in the future? 

Note: I could post more code, but I've narrowed the problem down to this line using Instruments and the full sample code is readily available to any developer.

Answer: 
Looking at the code for [KeyChainItemWrapper](http://developer.apple.com/library/ios/#samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_m.html), I'd agree that this line is a memory leak. They missed the `[attributes release]` at the end of `writeToKeychain`. See all the other calls to `SecItemCopyMatching()` in this file for examples of how they correctly release the returned-by-reference object.

I would use the "It's good, but..." link at the bottom of this page to note the error.
I found another one leak in `- (void) resetKeychainItem`.

It should be

`self.pKeychainItemData = [[[NSMutableDictionary alloc] init] autorelease];`.