diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 52cc60006..8eab6157d 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -465,6 +465,12 @@ module ObjectiveC = struct || String.is_substring ~substring:"Copy" procname ) + let is_core_foundation_create_or_copy _ procname = + String.is_prefix ~prefix:"CF" procname + && ( String.is_substring ~substring:"Create" procname + || String.is_substring ~substring:"Copy" procname ) + + let is_core_graphics_release _ procname = String.is_prefix ~prefix:"CG" procname && String.is_suffix ~suffix:"Release" procname diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index 5ac56189c..c52e45d2c 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -164,6 +164,8 @@ val is_override_of_java_lang_object_equals : Procname.t -> bool module ObjectiveC : sig val is_core_graphics_create_or_copy : Tenv.t -> string -> bool + val is_core_foundation_create_or_copy : Tenv.t -> string -> bool + val is_core_graphics_release : Tenv.t -> string -> bool val is_modelled_as_alloc : Tenv.t -> string -> bool diff --git a/infer/src/pulse/PulseModels.ml b/infer/src/pulse/PulseModels.ml index 903ea68d8..95680c6aa 100644 --- a/infer/src/pulse/PulseModels.ml +++ b/infer/src/pulse/PulseModels.ml @@ -674,6 +674,7 @@ module ProcNameDispatcher = struct $!--> fun x -> StdVector.at ~desc:"Enumeration.nextElement" x (AbstractValue.mk_fresh (), []) ) ; +PatternMatch.ObjectiveC.is_core_graphics_create_or_copy &++> C.malloc + ; +PatternMatch.ObjectiveC.is_core_foundation_create_or_copy &++> C.malloc ; +PatternMatch.ObjectiveC.is_core_graphics_release <>$ capt_arg_payload $--> C.free ; -"CFRelease" <>$ capt_arg_payload $--> C.free ; -"CFAutorelease" <>$ capt_arg_payload $--> C.free diff --git a/infer/tests/codetoanalyze/objc/pulse/Makefile b/infer/tests/codetoanalyze/objc/pulse/Makefile index a234390fb..f76937b71 100644 --- a/infer/tests/codetoanalyze/objc/pulse/Makefile +++ b/infer/tests/codetoanalyze/objc/pulse/Makefile @@ -7,7 +7,7 @@ TESTS_DIR = ../../.. CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS) -fobjc-arc INFER_OPTIONS = --pulse-only --debug-exceptions --project-root $(TESTS_DIR) \ ---pulse-model-alloc-pattern "AB[IF].*Create.*\|CFLocaleCreate" \ +--pulse-model-alloc-pattern "AB[IF].*Create.*" \ --pulse-model-free-pattern ABFRelease INFERPRINT_OPTIONS = --issues-tests diff --git a/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m b/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m index b516e0971..563986192 100644 --- a/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m +++ b/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m @@ -72,7 +72,12 @@ return CFBridgingRelease(nameRef); } -- (void)call_bridge_no_leak_good { +- (void)create_release_no_leak_ok { + CFLocaleRef nameRef = CFLocaleCreate(NULL, NULL); + CFRelease(nameRef); +} + +- (void)call_bridge_no_leak_ok { NSLocale* locale = [self ret_bridge]; }