diff --git a/infer/src/pulse/PulseModels.ml b/infer/src/pulse/PulseModels.ml index aa0a12b00..69f02943c 100644 --- a/infer/src/pulse/PulseModels.ml +++ b/infer/src/pulse/PulseModels.ml @@ -275,17 +275,6 @@ module StdAtomicInteger = struct [PulseExecutionState.ContinueProgram astate] end -module ObjectiveC = struct - let alloc _ : model = - fun ~caller_summary:_ ~callee_procname location ~ret:(ret_id, _) astate -> - let hist = - [ValueHistory.Allocation {f= Model (Procname.to_string callee_procname); location}] - in - let ret_addr = AbstractValue.mk_fresh () in - let astate = PulseOperations.allocate callee_procname location (ret_addr, hist) astate in - PulseOperations.write_id ret_id (ret_addr, hist) astate |> PulseOperations.ok_continue -end - module JavaObject = struct (* naively modeled as shallow copy. *) let clone src_pointer_hist : model = @@ -562,7 +551,7 @@ module ProcNameDispatcher = struct &:: "nextElement" <>$ capt_arg_payload $!--> fun x -> StdVector.at ~desc:"Enumeration.nextElement" x (AbstractValue.mk_fresh (), []) ) - ; +PatternMatch.ObjectiveC.is_core_graphics_create_or_copy &++> ObjectiveC.alloc + ; +PatternMatch.ObjectiveC.is_core_graphics_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/MemoryLeaks.m b/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m index 1811bd3c1..87b99d5bc 100644 --- a/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m +++ b/infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m @@ -37,8 +37,10 @@ + (void)cg_path_create_mutable_no_leak_good:(CGRect)rect { CGFloat lineThickness = 0.20f * CGRectGetHeight(rect); // One rectangle - CGMutablePathRef path1 = CGPathCreateMutable(); - CFRelease(path1); + CGMutablePathRef path = CGPathCreateMutable(); + if (!path) + return; + CFRelease(path); } + (void)cg_bitmap_context_create_image_no_leak_good {