facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.97k stars 2.02k forks source link

Infer need to report RESOURCE_LEAK bug #1627

Open ghost opened 2 years ago

ghost commented 2 years ago

Infer version: 1.1.0 Ubuntu version: 20.04 Command:

infer run --biabduction -- javac  Prog.java

Output:

Capturing in javac mode...
Found 1 source file to analyze in /path/to/infer-out
1/1 [################################################################################] 100% 36.624ms
No issues found

Code Example:

public class Prog {
  InflaterOutputStream printer;
  public void foo() {
    byte[] arr = {1, 2, 3};
    FileOutputStream fis;
    try {
      fis = new FileOutputStream("file.txt"); 
      printer = new InflaterOutputStream(fis, null);   
      for (int i = 0; i < 1; i++) {
        printer.write(arr);
      }
      // should report a warning here, because printer is not free
    } catch (IOException e) {}
  }
}