Page MenuHomePhabricator

[analyzer] RetainCount: Accept "safe" CFRetain wrappers.
ClosedPublic

Authored by NoQ on Oct 13 2017, 1:56 AM.

Details

Summary

CoreFoundation users often look for a "safe" wrapper around CFRetain and CFRelease that would gracefully accept (and ignore) a null CF reference. Users are trying to annotate it with CF_RETURNS_RETAINED, which misleads the analyzer into believing that the function kind of "creates" the object with a +1 retain count (such annotation is normally used on functions that create or copy objects), while in fact it increments the retain count on an existing object.

When modeling such function, RetainCountChecker first realizes that this function is merely a CFRetain (due to naming convention) and increments the reference count, and then sees the annotation and throws away the existing retain count information and resets the reference count to +1. This causes obvious problems, for example if the object is safely-retained and released more than once, it'd cause various kinds of overrelease warnings.

Tell the analyzer not to look at annotations for functions that he already identified as some form of CFRetain.

Diff Detail

Event Timeline

NoQ created this revision.Oct 13 2017, 1:56 AM
dcoughlin accepted this revision.Oct 13 2017, 10:36 AM
dcoughlin added a reviewer: george.karpenkov.

Looks good to me!

This revision is now accepted and ready to land.Oct 13 2017, 10:37 AM
This revision was automatically updated to reflect the committed changes.