From 3b919179bc7ef95195323cf068d302dee3f117b5 Mon Sep 17 00:00:00 2001 From: jrm Date: Mon, 7 Dec 2015 21:06:38 -0800 Subject: [PATCH] Add the type of the resource being leaked to the error message Summary: public The resource leak warning messages can sometimes be confusing especially when several type of resources are involved in the code where the warning is reported. This diff adds the class name of the resource being leaked to the error message. Reviewed By: sblackshear Differential Revision: D2706538 fb-gh-sync-id: ccf364e --- infer/src/backend/errdesc.ml | 2 +- infer/src/backend/localise.ml | 24 ++++++++++++++---------- infer/src/backend/localise.mli | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/infer/src/backend/errdesc.ml b/infer/src/backend/errdesc.ml index 0bb3e450d..2a7924ebe 100644 --- a/infer/src/backend/errdesc.ml +++ b/infer/src/backend/errdesc.ml @@ -529,7 +529,7 @@ let explain_leak tenv hpred prop alloc_att_opt bucket = if leak_from_list_abstraction hpred prop && value_str != None then Exceptions.Exn_user, bucket (* we don't know it's been allocated, but it's coming from list abstraction and we have a name *) else Exceptions.Exn_developer, Some (Mleak_buckets.ml_bucket_unknown_origin ()) in - exn_cat, Localise.desc_leak value_str resource_opt res_action_opt loc bucket + exn_cat, Localise.desc_leak hpred_typ_opt value_str resource_opt res_action_opt loc bucket (** find the dexp, if any, where the given value is stored also return the type of the value if found *) diff --git a/infer/src/backend/localise.ml b/infer/src/backend/localise.ml index f4abd3ea1..f56c22007 100644 --- a/infer/src/backend/localise.ml +++ b/infer/src/backend/localise.ml @@ -229,7 +229,6 @@ let by_call_to_ra tags ra = "by " ^ call_to_at_line tags ra.Sil.ra_pname ra.Sil.ra_loc let mem_dyn_allocated = "memory dynamically allocated" -let res_acquired = "resource acquired" let lock_acquired = "lock acquired" let released = "released" let reachable = "reachable" @@ -583,24 +582,29 @@ let desc_frontend_warning desc sugg loc = sugg in [description], None, !tags -let desc_leak value_str_opt resource_opt resource_action_opt loc bucket_opt = +let desc_leak hpred_type_opt value_str_opt resource_opt resource_action_opt loc bucket_opt = let tags = Tags.create () in let () = match bucket_opt with | Some bucket -> Tags.add tags Tags.bucket bucket; | None -> () in - let value_str = match value_str_opt with - | None -> "" - | Some s -> - Tags.add tags Tags.value s; - s in let xxx_allocated_to = + let value_str, _to, _on = + match value_str_opt with + | None -> "", "", "" + | Some s -> + Tags.add tags Tags.value s; + s, " to ", " on " in + let typ_str = + match hpred_type_opt with + | Some (Sil.Sizeof (Sil.Tstruct (_, _, Sil.Class, Some classname, _, _, _), _)) + when !Config.curr_language = Config.Java -> + " of type " ^ Mangled.to_string classname ^ " " + | _ -> " " in let desc_str = - let _to = if value_str_opt = None then "" else " to " in - let _on = if value_str_opt = None then "" else " on " in match resource_opt with | Some Sil.Rmemory _ -> mem_dyn_allocated ^ _to ^ value_str - | Some Sil.Rfile -> res_acquired ^ _to ^ value_str + | Some Sil.Rfile -> "resource" ^ typ_str ^ "aquired" ^ _to ^ value_str | Some Sil.Rlock -> lock_acquired ^ _on ^ value_str | Some Sil.Rignore | None -> if value_str_opt = None then "memory" else value_str in diff --git a/infer/src/backend/localise.mli b/infer/src/backend/localise.mli index 39ad6eec4..b80376e14 100644 --- a/infer/src/backend/localise.mli +++ b/infer/src/backend/localise.mli @@ -190,7 +190,7 @@ val desc_divide_by_zero : string -> Location.t -> error_desc val desc_frontend_warning : string -> string -> Location.t -> error_desc val desc_leak : - string option -> Sil.resource option -> Sil.res_action option -> + Sil.exp option -> string option -> Sil.resource option -> Sil.res_action option -> Location.t -> string option -> error_desc val desc_null_test_after_dereference : string -> int -> Location.t -> error_desc