You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
966 B

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
void __free_cf(CFTypeRef item);
[objc] Refactor modeling of CoreFoundation and CoreGraphics libraries Summary: The diff is very big but it's mostly removing code. It was inspired by the fact that we were getting Dead Store FPs because we were modeling some functions from CoreFoundation and CoreGraphics directly as alloc in the frontend, which caused the parameters of the function to be seen as dead. See the new test. To deal with this, if we are going to skip the function, we model it as malloc instead. Given how many models we had for those "model as malloc" functions, I removed them to rely solely on the new mechanism. The modeling of malloc and release was still based on the old retain count implementation, even though all we do here is a malloc/free kind of analysis. I also changed that to be actually malloc/free which removed many Assert false in the tests. CFRelease is not exactly free though, and it's possible to use the variable afterwards. So used a custom free builtin that only cares about removing the Memory attribute and focuses on minimizing Memory Leaks FPs. Otherwise we were translating CFBridgingRelease as a special cast, and this wasn't working. To simplify this as well, I removed all the code for the special cast, and just modeled CFBridgingRelease and CFAutorelease also as free_cf, to avoid Memory Leak false positives. I also treated the cast __bridge_transfer as a free_cf model. This means we stopped trying to report Memory Leaks on those objects. The modeling of CoreGraph release functions was done in the frontend, but seemed simpler to also simplify that code and model all the relevant functions. Reviewed By: sblackshear Differential Revision: D6397150 fbshipit-source-id: b1dc636
7 years ago
void CFRelease(CFTypeRef item) { __free_cf(item); }
CFRunLoopObserverRef getAngelicObject();
CFRunLoopObserverRef CFRunLoopObserverCreateWithHandler(
CFAllocatorRef allocator,
CFOptionFlags activities,
Boolean repeats,
CFIndex order,
void (^block)(CFRunLoopObserverRef observer, CFRunLoopActivity activity)) {
// We need to skip allocation for this function since we currently don't
// handle object finalizers in objc. This is to avoid false positive memory
// leaks when the 'observer' is correctly freed in the block argument.
// undefined function will get skipped and thus make
// CFRunLoopObserverCreateWithHandler return an angelic object
return getAngelicObject();
}