Add CFRunLoopObserverCreateWithHandler model and test

Reviewed By: dulmarod

Differential Revision: D8713250

fbshipit-source-id: 7e9761c
master
Martin Trojer 7 years ago committed by Facebook Github Bot
parent e667c32324
commit d442937380

@ -7,3 +7,18 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
void CFRelease(CFTypeRef item) { __free_cf(item); } void CFRelease(CFTypeRef item) { __free_cf(item); }
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();
}

@ -27,6 +27,7 @@ SOURCES_DEFAULT = \
memory_leaks_benchmark/RetainReleaseExampleBucketing.m \ memory_leaks_benchmark/RetainReleaseExampleBucketing.m \
memory_leaks_benchmark/CoreVideoExample.m \ memory_leaks_benchmark/CoreVideoExample.m \
memory_leaks_benchmark/RetainCycleLength3.m \ memory_leaks_benchmark/RetainCycleLength3.m \
memory_leaks_benchmark/ReleasedInBlock.m \
npe/dynamic_dispatch.m \ npe/dynamic_dispatch.m \
npe/Fraction.m \ npe/Fraction.m \
npe/NPD_core_foundation.m \ npe/NPD_core_foundation.m \

@ -0,0 +1,21 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* 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 allocAndReleaseInBlock() {
void (^callback)(CFRunLoopObserverRef obs, CFRunLoopActivity activity) =
^(CFRunLoopObserverRef obs, CFRunLoopActivity activity) {
// We should check if the object is released properly, see
// infer/models/objc/src/CoreFoundation.c
CFRelease(obs);
};
CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler(
NULL, kCFRunLoopBeforeWaiting, NO, UINT_MAX, callback);
CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes);
}
Loading…
Cancel
Save