jrendel / SwiftKeychainWrapper

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.
MIT License
1.59k stars 339 forks source link

UnsafeMutablePointer causing app crash #92

Closed garie closed 5 years ago

garie commented 7 years ago

My app is crashing on the line SecItemCopyMatching(keychainQueryDictionary as CFDictionary, UnsafeMutablePointer($0)) in some cases. It breaks with EXC_BAD_ACCESS but does not print a stack trace, even with zombies on. I believe it is the UnsafeMutablePointer causing the issue because I can see in the thread at the side, the last call before this line is withUnsafeMutablePointer. Here is a screenshot of the thread:

screen shot 2017-04-05 at 11 47 18 am

This is my code that is causing the problem:

private let keychain: KeychainWrapper
...
func something() {
    var data = [String : String]()
    data[UserInfo.Key.idToken] = self.keychain.string(forKey: "id_token", withAccessibility: KeychainItemAccessibility.afterFirstUnlockThisDeviceOnly)
}

I believe I will be able to avoid this issue by changing how I am doing things in my app so that this line is not called in this situation, but I figured I would file the issue anyway.

gtimmy commented 7 years ago

I had exactly the same issue on macOS with some of the old version of KeychainWrapper. Are there any updates?

jrendel commented 7 years ago

I've made a fix for this in the develop branch based on new guidelines for working with UnsafeMutablePointer. Hopefully this will help with the issue you've seen. For now this is just in the develop branch until I can do some more testing.

jordanpwood commented 6 years ago

I am also getting a crash here, but only on a very small percentage of my users (like 0.5% or so). Have you done any more testing on this issue?

jordanpwood commented 6 years ago

To update this issue, I switched to the the fix in the develop branch, and my small % of crashes went away, and I haven't seen any other side effects.

jrendel commented 5 years ago

This has been updated officially in 3.2 now and pushed to CocoaPods.