From 485d5c030ede779b0759efb26f38ff193848d98e Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 14 Aug 2015 09:17:37 -0600 Subject: [PATCH] [Infer][activity leaks] Turning on Activity leak reporting Summary: Making Activity leak error messages production-ready and turning off filtering of leak alarms. --- infer/bin/inferlib.py | 3 ++- infer/src/backend/errdesc.ml | 4 ++-- infer/src/backend/errdesc.mli | 2 +- infer/src/backend/interproc.ml | 6 +++--- infer/src/backend/localise.ml | 8 +++++--- infer/src/backend/localise.mli | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/infer/bin/inferlib.py b/infer/bin/inferlib.py index 8ee9cb403..3bb5bf92d 100644 --- a/infer/bin/inferlib.py +++ b/infer/bin/inferlib.py @@ -250,7 +250,8 @@ def should_report(analyzer, row): 'RESOURCE_LEAK', 'MEMORY_LEAK', 'RETAIN_CYCLE', - 'ASSERTION_FAILURE' + 'ASSERTION_FAILURE', + 'ACTIVITY_LEAK' ] if analyzer in [ERADICATE, CHECKERS, TRACING]: diff --git a/infer/src/backend/errdesc.ml b/infer/src/backend/errdesc.ml index 7f7b0052c..97ea48559 100644 --- a/infer/src/backend/errdesc.ml +++ b/infer/src/backend/errdesc.ml @@ -27,8 +27,8 @@ let hpred_is_open_resource prop = function None (** Produce a description of a persistent reference to an Android Activity *) -let explain_activity_leak activity_typ fieldname = - Localise.desc_activity_leak activity_typ fieldname +let explain_activity_leak pname activity_typ fieldname = + Localise.desc_activity_leak pname activity_typ fieldname (** Explain a deallocate stack variable error *) let explain_deallocate_stack_var pvar ra = diff --git a/infer/src/backend/errdesc.mli b/infer/src/backend/errdesc.mli index 733c0b71d..ba57f6291 100644 --- a/infer/src/backend/errdesc.mli +++ b/infer/src/backend/errdesc.mli @@ -41,7 +41,7 @@ val find_boolean_assignment : Cfg.Node.t -> Sil.pvar -> bool -> Cfg.Node.t optio val exp_rv_dexp : Cfg.Node.t -> Sil.exp -> Sil.dexp option (** Produce a description of a persistent reference to an Android Activity *) -val explain_activity_leak : Sil.typ -> Ident.fieldname -> Localise.error_desc +val explain_activity_leak : Procname.t -> Sil.typ -> Ident.fieldname -> Localise.error_desc (** Produce a description of a mismatch between an allocation function and a deallocation function *) val explain_allocation_mismatch : Sil.res_action -> Sil.res_action -> Localise.error_desc diff --git a/infer/src/backend/interproc.ml b/infer/src/backend/interproc.ml index 4dd381eb4..41ed204b3 100644 --- a/infer/src/backend/interproc.ml +++ b/infer/src/backend/interproc.ml @@ -591,7 +591,7 @@ let forward_tabulate cfg tenv = L.d_strln ".... Work list empty. Stop ...."; L.d_ln () (** report an error if any Activity is reachable from a static field *) -let report_activity_leaks sigma tenv = +let report_activity_leaks pname sigma tenv = (* report an error if an expression in [activity_exps] is reachable from [field_strexp] *) let check_reachable_activity_from_fld (fld_name, fld_strexp) activity_exps = let _, reachable_exps = @@ -601,7 +601,7 @@ let report_activity_leaks sigma tenv = list_iter (fun (activity_exp, typ) -> if Sil.ExpSet.mem activity_exp reachable_exps then - let err_desc = Errdesc.explain_activity_leak typ fld_name in + let err_desc = Errdesc.explain_activity_leak pname typ fld_name in raise (Exceptions.Activity_leak (err_desc, try assert false with Assert_failure x -> x))) activity_exps in (* get the set of pointed-to expressions of type T <: Activity *) @@ -680,7 +680,7 @@ let extract_specs tenv pdesc pathset : Prop.normal Specs.spec list = (* let () = L.out "@.AFTER abs:@.$%a@." (Prop.pp_prop Utils.pe_text) prop'' in *) let pre, post = Prop.extract_spec prop'' in let pre' = Prop.normalize (Prop.prop_sub sub pre) in - if !Sil.curr_language = Sil.Java then report_activity_leaks (Prop.get_sigma post) tenv; + if !Sil.curr_language = Sil.Java then report_activity_leaks pname (Prop.get_sigma post) tenv; let post' = if Prover.check_inconsistency_base prop then None else Some (Prop.normalize (Prop.prop_sub sub post), path) in diff --git a/infer/src/backend/localise.ml b/infer/src/backend/localise.ml index 19b12ad80..b02375860 100644 --- a/infer/src/backend/localise.ml +++ b/infer/src/backend/localise.ml @@ -364,10 +364,12 @@ let java_unchecked_exn_desc proc_name exn_name pre_str : error_desc = "can throw "^(Mangled.to_string exn_name); "whenever "^pre_str], None, []) -let desc_activity_leak activity_typ fieldname : error_desc = - let activity_str = Sil.typ_to_string activity_typ in +let desc_activity_leak pname activity_typ fieldname : error_desc = + let pname_str = Procname.java_get_class pname ^ "." ^ Procname.java_get_method pname in + (* intentionally omit space; [typ_to_string] adds an extra space *) + let activity_str = Sil.typ_to_string activity_typ ^ "may leak via static field" in let fld_str = Ident.fieldname_to_string fieldname in - (["Activity subclass"; activity_str; "may leak via static field"; fld_str], None, []) + (["Activity"; activity_str; fld_str; "during call to"; pname_str], None, []) let desc_assertion_failure loc : error_desc = (["could be raised"; at_line (Tags.create ()) loc], None, []) diff --git a/infer/src/backend/localise.mli b/infer/src/backend/localise.mli index 44b997acc..412e1e3c7 100644 --- a/infer/src/backend/localise.mli +++ b/infer/src/backend/localise.mli @@ -190,7 +190,7 @@ val desc_null_test_after_dereference : string -> int -> Sil.location -> error_de val java_unchecked_exn_desc : Procname.t -> Mangled.t -> string -> error_desc -val desc_activity_leak : Sil.typ -> Ident.fieldname -> error_desc +val desc_activity_leak : Procname.t -> Sil.typ -> Ident.fieldname -> error_desc (* Create human-readable error description for assertion failures *) val desc_assertion_failure : Sil.location -> error_desc @@ -220,4 +220,4 @@ val desc_unary_minus_applied_to_unsigned_expression : string option -> string -> val desc_tainted_value_reaching_sensitive_function : string -> Sil.location -> error_desc -val desc_uninitialized_dangling_pointer_deref : deref_str -> string -> Sil.location -> error_desc \ No newline at end of file +val desc_uninitialized_dangling_pointer_deref : deref_str -> string -> Sil.location -> error_desc