CFRelease crash in iOS10

后端 未结 1 1455
情歌与酒
情歌与酒 2021-01-26 09:13

Below is my code, which used to work fine till iOS 9.

- (NSData *)encryptWithDataPublicKey:(NSString*)data keyTag:(NSString*)tag
{  

    SecKeyRef publicKey = N         


        
1条回答
  •  暖寄归人
    2021-01-26 09:42

    In encryptData:withKeyRef: you have an unbalanced CFRelease at the end of the method. Nothing in that method retained keyRef, but you release it. Remove that call.

    Why didn't it crash before? Because something else was likely retaining it internally previously, possibly a cache, possibly something else. Cocoa makes no promises that an over-release will immediately (or ever) lead to a crash. You were into undefined behavior.

    It's very distressing, though, that the static analyzer isn't detecting this. I would open a bug report about that (bugreport.apple.com). You have a very clear memory management violation and the analyzer should have caught it.

    0 讨论(0)
提交回复
热议问题