OSArray*arr=OSArray::withCapacity(10);// expected-note{{Call to function 'withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}}
arr->getCount();// expected-warning{{Reference-counted object is used after it is released}}
// expected-note@-1{{Reference-counted object is used after it is released}}
}
voidpotential_leak(){
OSArray*arr=OSArray::withCapacity(10);// expected-note{{Call to function 'withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}}
arr->retain();// expected-note{{Reference count incremented. The object now has a +2 retain count}}
arr->release();// expected-note{{Reference count decremented. The object now has a +1 retain count}}
arr->getCount();
}// expected-warning{{Potential leak of an object stored into 'arr'}}
// expected-note@-1{{Object leaked: object allocated and stored into 'arr' is not referenced later in this execution path and has a retain count of +1}}
voidproper_cleanup(){
OSArray*arr=OSArray::withCapacity(10);// +1
arr->retain();// +2
arr->release();// +1
arr->getCount();
arr->release();// 0
}
structArrayOwner{
OSArray*arr;
OSArray*getArray(){
returnarr;
}
OSArray*createArray(){
returnOSArray::withCapacity(10);
}
OSArray*createArraySourceUnknown();
OSArray*getArraySourceUnknown();
};
//unsigned int leak_on_create_no_release(ArrayOwner *owner) {