2

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__*/
}
griotspeak
  • 13,022
  • 13
  • 43
  • 54
  • You have **two** values created following 'Create' rules, and you release only **one** `value`, `adjustedValue` is never released. In your sample the warning seems correct to me. – Emmanuel Dec 22 '13 at 08:55
  • @Emmanuel This is a 'Create' function, besides which, it is still not a leak. I am returning a reference to the value that I did not release. – griotspeak Dec 22 '13 at 14:30
  • Your modification changes everything concerning my previous comment, which is no more valid. – Emmanuel Dec 22 '13 at 15:06

0 Answers0