objective-c - 应用程序因 Objective-C 中的错误“Invalid pointer dequeued from free list”而崩溃
问题描述
当我们为 AES 加密/解密生成密钥时,我收到以下错误。
malloc: *** error for object 0x1c421b840: Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
下面添加了生成密钥的代码:
- (NSData*)generateKey:(NSString*)childKey {
unsigned char saltChar[16];
for (int i=0; i<16; i++) {
saltChar[i] = 0;
}
NSData *salt = [NSData dataWithBytes:saltChar length:16];
size_t bufferSize = kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
int result = CCKeyDerivationPBKDF(kCCPBKDF2, // algorithm
childKey.UTF8String, // password
[childKey lengthOfBytesUsingEncoding:NSUTF8StringEncoding], // passwordLength
salt.bytes, // salt
salt.length, // saltLen
kCCPRFHmacAlgSHA1, // PRF
65, // rounds
buffer, // derivedKey
bufferSize*8); // derivedKeyLen
NSLog(@"Unable to create AES key for password: %d", result);
NSData *data = nil;
if (result == kCCSuccess) {
data = [[NSData alloc] initWithData:[NSData dataWithBytesNoCopy:buffer length:16]];
}
free(buffer);
return data;
}
上面的代码出了什么问题,我对这个错误感到非常沮丧。请帮助任何人。
提前致谢。
解决方案
推荐阅读
- java - 如何使用流为 hashmap 实现 isEmpty()?
- loops - Ansible:遍历字典列表 - 循环与 with_items
- django - 图片不在 django 中提供
- c# - Web (ASP.Net) Wcf:未找到从桌面客户端连接时出错
- python - Pandas 基于 2 列删除重复项,有时会颠倒
- php - 有没有办法使用 PHP 表单循环浏览数据库中的多个记录?
- java - 我是否正确使用了 Scanner 和 File 类?
- reactjs - 如何将数据传递给功能组件?
- javascript - 使用点击生物创建团队页面
- html - 有没有办法让子 div 的背景扩展到父 div 之外?