Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Copying configuration values of NSString

#60

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.

Reported by Adam Alexander · March 10th, 2009 @ 12:01 AM

State: new
Assigned to: nobody

Activity

  1. Adam Alexander
    Adam Alexander

    The actual commit is here, which is currently the HEAD of the branch I linked above:

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

    March 10th, 2009 @ 12:02 AM

  2. Joshua Vickery
    Joshua Vickery
    • Milestone set to ObjectiveResource 1.1

    March 11th, 2009 @ 07:44 AM

  3. Joshua Vickery

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.