I have some opaque types and have implemented a reference counting semantic that mimics Core Foundation. This works well enough except that clang warns me of semi valid potential leaks.
MyTypeRef MyTypeRefCreateWithSomething(…) {
MyTypeRef value = MyTypeRefCreate(…);
MyTypeRef adjustedValue = MyTypeRefCreate(…);
MyTypeRefRelease(value);
return adjustedValue; // clang says that this might be a leak of `value`…
// which is only true if something goes wrong with reference counting.
}
I am looking for something like attribute_cf_consumed
or a simple way to make my own version.
For reference, this is how I currently silence the warning. It works but it is, in my opinion, as bad as just leaving the warnings in. (I ifdef the if
statement that surrounds MytypeRelease
's call to free
)
void MyTypeRelease(MyTypeRef degree) {
((MyMutableTypeRef)degree)->refCount--;
#ifndef __clang_analyzer__
if ((degree->refCount <= 0) && !MyTypeIsNull(degree)) {
#endif /*__clang_analyzer__*/
free((CTJUMTMutableScaleDegree)degree);
#ifndef __clang_analyzer__
}
#endif /*__clang_analyzer__*/
}