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
master
jrm 9 years ago committed by facebook-github-bot-7
parent 5a218a6d02
commit 3b919179bc

@ -529,7 +529,7 @@ let explain_leak tenv hpred prop alloc_att_opt bucket =
if leak_from_list_abstraction hpred prop && value_str != None 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 *) 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 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 (** find the dexp, if any, where the given value is stored
also return the type of the value if found *) also return the type of the value if found *)

@ -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 "by " ^ call_to_at_line tags ra.Sil.ra_pname ra.Sil.ra_loc
let mem_dyn_allocated = "memory dynamically allocated" let mem_dyn_allocated = "memory dynamically allocated"
let res_acquired = "resource acquired"
let lock_acquired = "lock acquired" let lock_acquired = "lock acquired"
let released = "released" let released = "released"
let reachable = "reachable" let reachable = "reachable"
@ -583,24 +582,29 @@ let desc_frontend_warning desc sugg loc =
sugg in sugg in
[description], None, !tags [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 tags = Tags.create () in
let () = match bucket_opt with let () = match bucket_opt with
| Some bucket -> | Some bucket ->
Tags.add tags Tags.bucket bucket; Tags.add tags Tags.bucket bucket;
| None -> () in | 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 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 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 match resource_opt with
| Some Sil.Rmemory _ -> mem_dyn_allocated ^ _to ^ value_str | 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.Rlock -> lock_acquired ^ _on ^ value_str
| Some Sil.Rignore | Some Sil.Rignore
| None -> if value_str_opt = None then "memory" else value_str in | None -> if value_str_opt = None then "memory" else value_str in

@ -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_frontend_warning : string -> string -> Location.t -> error_desc
val desc_leak : 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 Location.t -> string option -> error_desc
val desc_null_test_after_dereference : string -> int -> Location.t -> error_desc val desc_null_test_after_dereference : string -> int -> Location.t -> error_desc

Loading…
Cancel
Save