From d25754597dcb40fd2b3d4e7e6b73042a7da31c41 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Mon, 4 Dec 2017 03:45:55 -0800 Subject: [PATCH] [memory leaks] Adding model for CVPixelBufferRelease Reviewed By: da319 Differential Revision: D6458051 fbshipit-source-id: a61ffb9 --- infer/models/objc/src/CoreVideo.c | 12 ++++++++ .../tests/codetoanalyze/objc/errors/Makefile | 1 + .../codetoanalyze/objc/errors/issues.exp | 1 + .../memory_leaks_benchmark/CoreVideoExample.m | 29 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 infer/models/objc/src/CoreVideo.c create mode 100644 infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/CoreVideoExample.m diff --git a/infer/models/objc/src/CoreVideo.c b/infer/models/objc/src/CoreVideo.c new file mode 100644 index 000000000..39260e94a --- /dev/null +++ b/infer/models/objc/src/CoreVideo.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import +#import + +void CVPixelBufferRelease(CVPixelBufferRef pxbuffer) { __free_cf(pxbuffer); } diff --git a/infer/tests/codetoanalyze/objc/errors/Makefile b/infer/tests/codetoanalyze/objc/errors/Makefile index 19a53dee9..3395e781b 100644 --- a/infer/tests/codetoanalyze/objc/errors/Makefile +++ b/infer/tests/codetoanalyze/objc/errors/Makefile @@ -27,6 +27,7 @@ SOURCES_DEFAULT = \ memory_leaks_benchmark/NSString_models_tests.m \ memory_leaks_benchmark/NSData_models_tests.m \ memory_leaks_benchmark/RetainReleaseExampleBucketing.m \ + memory_leaks_benchmark/CoreVideoExample.m \ npe/Fraction.m \ npe/NPD_core_foundation.m \ npe/Npe_with_equal_names.m \ diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index d46bb50bc..7502090c4 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -73,6 +73,7 @@ codetoanalyze/objc/errors/subtyping/KindOfClassExample.m, shouldThrowDivideByZer codetoanalyze/objc/errors/subtyping/KindOfClassExample.m, shouldThrowDivideByZero2, 2, DIVIDE_BY_ZERO, [start of procedure shouldThrowDivideByZero2(),start of procedure init,return from a call to Base_init,start of procedure returnsZero2(),Condition is false,return from a call to returnsZero2] codetoanalyze/objc/errors/subtyping/KindOfClassExample.m, shouldThrowDivideByZero3, 3, DIVIDE_BY_ZERO, [start of procedure shouldThrowDivideByZero3(),start of procedure init,return from a call to Derived_init,Condition is true] codetoanalyze/objc/errors/variadic_methods/premature_nil_termination.m, PrematureNilTermA_nilInArrayWithObjects, 5, PREMATURE_NIL_TERMINATION_ARGUMENT, [start of procedure nilInArrayWithObjects] +codetoanalyze/objc/errors/memory_leaks_benchmark/CoreVideoExample.m, CoreVideoExample_cvpixelbuffer_not_released_leak, 1, MEMORY_LEAK, [start of procedure cvpixelbuffer_not_released_leak] codetoanalyze/objc/errors/memory_leaks_benchmark/NSData_models_tests.m, NSData_models_tests_macForIV:, 2, MEMORY_LEAK, [start of procedure macForIV:] codetoanalyze/objc/errors/memory_leaks_benchmark/NSString_models_tests.m, StringInitA_hexStringValue, 11, MEMORY_LEAK, [start of procedure hexStringValue,Skipping CFStringCreateWithBytesNoCopy(): function or method not found,Condition is false] codetoanalyze/objc/errors/npe/Fraction.m, test_virtual_call, 7, NULL_DEREFERENCE, [start of procedure test_virtual_call(),start of procedure setNumerator:,return from a call to Fraction_setNumerator:,start of procedure getNumerator,return from a call to Fraction_getNumerator,Condition is true] diff --git a/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/CoreVideoExample.m b/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/CoreVideoExample.m new file mode 100644 index 000000000..d7dc20c0c --- /dev/null +++ b/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/CoreVideoExample.m @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import +#import +#import + +CVPixelBufferRef MyCVPixelBufferCreate(); + +@interface CoreVideoExample : NSObject + +@end + +@implementation CoreVideoExample + +- (void)cvpixelbuffer_released_no_leak { + CVPixelBufferRef pxbuffer = MyCVPixelBufferCreate(); + CVPixelBufferRelease(pxbuffer); +} + +- (void)cvpixelbuffer_not_released_leak { + CVPixelBufferRef pxbuffer = MyCVPixelBufferCreate(); +} +@end