model Inflater and Deflater as resources

Summary: public
The classes `java.util.zip.{Inflater/Deflater}` where not modelled as resources. In practice, bad memory leak can happen using these classes and forcing the call to `end()` can help to avoid waisting native memory.

Reviewed By: sblackshear

Differential Revision: D2661249

fb-gh-sync-id: 1e33316
master
jrm 9 years ago committed by facebook-github-bot-7
parent 12e37c97fc
commit 930eaba2d5

@ -0,0 +1,32 @@
/*
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package java.util.zip;
import com.facebook.infer.models.InferBuiltins;
public class Deflater {
public Deflater() {
InferBuiltins.__set_file_attribute(this);
}
public Deflater(int level) {
this();
}
public Deflater(int level, boolean nowrap) {
this();
}
public void end() {
InferBuiltins.__set_mem_attribute(this);
}
}

@ -0,0 +1,28 @@
/*
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package java.util.zip;
import com.facebook.infer.models.InferBuiltins;
public class Inflater {
public Inflater() {
InferBuiltins.__set_file_attribute(this);
}
public Inflater(boolean nowrap) {
this();
}
public void end() {
InferBuiltins.__set_mem_attribute(this);
}
}

@ -229,6 +229,11 @@
"file": "codetoanalyze/java/infer/FilterInputStreamLeaks.java", "file": "codetoanalyze/java/infer/FilterInputStreamLeaks.java",
"bug_type": "RESOURCE_LEAK" "bug_type": "RESOURCE_LEAK"
}, },
{
"procedure": "void ResourceLeaks.deflaterLeak()",
"file": "codetoanalyze/java/infer/ResourceLeaks.java",
"bug_type": "RESOURCE_LEAK"
},
{ {
"procedure": "void FilterOutputStreamLeaks.deflaterOutputStreamNotClosedAfterWrite()", "procedure": "void FilterOutputStreamLeaks.deflaterOutputStreamNotClosedAfterWrite()",
"file": "codetoanalyze/java/infer/FilterOutputStreamLeaks.java", "file": "codetoanalyze/java/infer/FilterOutputStreamLeaks.java",
@ -364,6 +369,11 @@
"file": "codetoanalyze/java/infer/FilterInputStreamLeaks.java", "file": "codetoanalyze/java/infer/FilterInputStreamLeaks.java",
"bug_type": "RESOURCE_LEAK" "bug_type": "RESOURCE_LEAK"
}, },
{
"procedure": "void ResourceLeaks.inflaterLeak()",
"file": "codetoanalyze/java/infer/ResourceLeaks.java",
"bug_type": "RESOURCE_LEAK"
},
{ {
"procedure": "void FilterOutputStreamLeaks.inflaterOutputStreamNotClosedAfterWrite()", "procedure": "void FilterOutputStreamLeaks.inflaterOutputStreamNotClosedAfterWrite()",
"file": "codetoanalyze/java/infer/FilterOutputStreamLeaks.java", "file": "codetoanalyze/java/infer/FilterOutputStreamLeaks.java",

@ -229,6 +229,11 @@
"file": "infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java", "file": "infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java",
"bug_type": "RESOURCE_LEAK" "bug_type": "RESOURCE_LEAK"
}, },
{
"procedure": "void ResourceLeaks.deflaterLeak()",
"file": "infer/tests/codetoanalyze/java/infer/ResourceLeaks.java",
"bug_type": "RESOURCE_LEAK"
},
{ {
"procedure": "void FilterOutputStreamLeaks.deflaterOutputStreamNotClosedAfterWrite()", "procedure": "void FilterOutputStreamLeaks.deflaterOutputStreamNotClosedAfterWrite()",
"file": "infer/tests/codetoanalyze/java/infer/FilterOutputStreamLeaks.java", "file": "infer/tests/codetoanalyze/java/infer/FilterOutputStreamLeaks.java",
@ -364,6 +369,11 @@
"file": "infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java", "file": "infer/tests/codetoanalyze/java/infer/FilterInputStreamLeaks.java",
"bug_type": "RESOURCE_LEAK" "bug_type": "RESOURCE_LEAK"
}, },
{
"procedure": "void ResourceLeaks.inflaterLeak()",
"file": "infer/tests/codetoanalyze/java/infer/ResourceLeaks.java",
"bug_type": "RESOURCE_LEAK"
},
{ {
"procedure": "void FilterOutputStreamLeaks.inflaterOutputStreamNotClosedAfterWrite()", "procedure": "void FilterOutputStreamLeaks.inflaterOutputStreamNotClosedAfterWrite()",
"file": "infer/tests/codetoanalyze/java/infer/FilterOutputStreamLeaks.java", "file": "infer/tests/codetoanalyze/java/infer/FilterOutputStreamLeaks.java",

@ -42,8 +42,10 @@ import java.util.Scanner;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.zip.Deflater;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import java.util.zip.Inflater;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -912,4 +914,22 @@ public class ResourceLeaks {
f.close(); f.close();
} }
public void deflaterLeak() {
Deflater comp = new Deflater();
}
public void deflaternoLeak() {
Deflater comp = new Deflater();
comp.end();
}
public void inflaterLeak() {
Inflater decomp = new Inflater();
}
public void inflaterNoLeak() {
Inflater decomp = new Inflater();
decomp.end();
}
} }

@ -74,6 +74,8 @@ public class ResourceLeaksTest {
"copyFileLeak", "copyFileLeak",
"copyFileLeak", "copyFileLeak",
"scannerNotClosed", "scannerNotClosed",
"deflaterLeak",
"inflaterLeak",
}; };
assertThat( assertThat(
"Results should contain the following resource leak errors", "Results should contain the following resource leak errors",

Loading…
Cancel
Save