Reporting false positives when detecting leaks of SQLiteDatabase cursors
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
Dear Infer developers,
I am trying Infer on some Android projects. I found that Infer will report false positives when detecting the leaks of Android sqlite database cursors. See the code below. The version of Infer I am using now is v0.9.4-8d48c10.
```
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.io.File;
import java.io.FileInputStream;
public class HelloWorld {
public void foo() {
Cursor c = null;
try {
SQLiteDatabase db = SQLiteDatabase.openDatabase("myDb", null, SQLiteDatabase.CREATE_IF_NECESSARY);
c = db.rawQuery("SELECT * FROM student where id='1'", null);
} finally{
if(c != null && !c.isClosed()){
c.close();
}
}
}
public void bar() throws Exception {
FileInputStream fis = null;
try {
fis = new FileInputStream(new File("myfile.txt"));
} finally {
if(fis != null) {
fis.close();
}
}
}
}
```
In the foo() method, the cursor c is closed in the finally block, but Infer still reports the leak of c. Interestingly, for the input stream used in bar(), which is also closed in the finally block, Infer does not report any leak. I don't understand why there is such difference? The two resources, i.e., cursor and input stream, are used and closed in a similar way. Is it a bug of Infer? Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.