From 2382e3d6134f2acddb1812d19037ca8f57252876 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Tue, 14 Apr 2020 02:41:29 -0700 Subject: [PATCH] [pulse] Model Core Graphics Create and Copy just like malloc Summary: Unify the models of malloc and for the Create and Copy functions for Core Graphics. This add the null case from the malloc model to the Core Graphics models. Reviewed By: jvillard Differential Revision: D20890956 fbshipit-source-id: 278ac9d2f --- infer/src/pulse/PulseModels.ml | 13 +------------ infer/tests/codetoanalyze/objc/pulse/MemoryLeaks.m | 6 ++++-- 2 files changed, 5 insertions(+), 14 deletions(-) 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 {