Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New feature] A rule to check about calling close_in/out after open_in/out #173

Open
david-maison opened this issue Apr 13, 2018 · 0 comments

Comments

@david-maison
Copy link

A new idea for a rule: is a possible to check if the function close_in (resp. close_out) is always called for each opened in_channel (resp. out_channel) before the end of its lifetime?

We can assume that it should be done in the same scope as the open_in (resp. open_out).

Examples:

let f name =
  try
    let out = open_out name in
    let text = compute_something () in
    output_string out text;
    close_out out
  with _ ->
    Format.eprintf "Error@."

Should warn about not closing out if an exception is raised between the open and close.

let f name =
  let out = open_out name in
  try
    let text = compute_something () in
    output_string out text;
    close_out out
  with _ ->
    Format.eprintf "Error@.";
    close_out out

Should be ok.

let f name =
  try
    let out = open_out name in
    compute_something out
  with _ ->
    Format.eprintf "Error@."

Should warn even if out is always closed in compute_something.

What do you think about this?
Comments (even negative ones!) and suggestions are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant