프로젝트를 ARC로 변환했으며 누수 계측기에서이 기능은 반복적으로 누출로 태그가 지정됩니다.ARC 누출 기능
나는 objc_release가 해결책일지도 모른다고 생각했지만 xCode는 그것을 좋아하지 않는다. 함수 내에서 호출
- (int)getNumber{
int result = 0;
unsigned char *myBytes = (unsigned char *)malloc(sizeof(char));
[stream getBytes:myBytes range:NSMakeRange(0, sizeof(char))];
char tag = myBytes[0];
if((int)tag >= 0){
result = (int)tag - 64;
}
else if ((int)tag == -64) {
[self removeChar];
result = [self getInt];
}
else
{
[self removeChar];
unsigned char *byteTwo = (unsigned char *)malloc(sizeof(char));
[stream getBytes:byteTwo range:NSMakeRange(0, sizeof(char))];
char twoTag = byteTwo[0];
result =
((((int)tag & 0x03f) << 8) |
(twoTag & 0x0ff)) ;
result -= 8192;
}
return result;
}
두 기능은
- (void)removeChar{
[stream replaceBytesInRange:NSMakeRange(0, 1) withBytes:NULL length:0];
}
및
- (int)getInt{
NSRange intRange = NSMakeRange(0,3);
char buffer[4];
[stream getBytes:buffer length:4];
[stream replaceBytesInRange:intRange withBytes:NULL length:0];
return (int) (
(((int)buffer[0] & 0xff) << 24) |
(((int)buffer[1] & 0xff) << 16) |
(((int)buffer[2] & 0xff) << 8) |
((int)buffer[3] & 0xff));
}이다
'malloc'없이'free'? 그건 누출처럼 보입니다 ...하지만 내가 이해하지 못하는 뭔가가있을 수 있습니다. 정적 분석기는 무엇을 말합니까? – matt