#60 new
Adam Alexander

Copying configuration values of NSString

Reported by Adam Alexander | March 10th, 2009 @ 12:01 AM | in ObjectiveResource 1.1

I've begun using the keychain for local password storage and in doing so uncovered an issue. When using:

[ObjectiveResourceConfig setPassword:myStringValue]

The string was not being copied or retained by ObjectiveResource. In my case the NSString was being returned by the keychain layer with a return count of 1 and set to autorelease, which means it is not long for the world unless the code which needs it to stick around copies or retains it. As a result my app would crash as soon as an attempt was made to retrieve the value that was set. To fix this I implemented a copy-property pattern on all four of the string values currently supported in the configuration:

http://github.com/adamalex/objec...

I verified this fixes the issue. I believe it didn't come up before because in most cases NSString values are optimized with an artificially-high return count to cause them to act more like constants. This is not guaranteed however and I found one of the edge cases! As long as the code which is responsible for the string copies or retains it then it will definitely be available when needed.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Port of Rails' ActiveResource framework to the iPhone.

Shared Ticket Bins

People watching this ticket

Pages