更新时间:2023-11-18 12:52:22
您需要free
个字节,因为NSData
不拥有它的所有权:它不知道该数组是临时数组还是动态数组,因此它会复制它.
You need to free
the bytes, because NSData
does not take ownership of it: it cannot know if the array is a temporary or a dynamic, so it makes a copy of it.
要解决此问题,请替换
return [NSData dataWithBytes:bytes length:c];
使用
NSData *res = [NSData dataWithBytes:bytes length:c];
free(bytes);
return res;