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

ZOOKEEPER-4246: Resource leaks in org.apache.zookeeper.server.persistence.SnapStream#getInputStream and #getOutputStream #1638

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -102,18 +102,23 @@ public static StreamMode fromString(String name) {
public static CheckedInputStream getInputStream(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
InputStream is;
switch (getStreamMode(file.getName())) {
case GZIP:
is = new GZIPInputStream(fis);
break;
case SNAPPY:
is = new SnappyInputStream(fis);
break;
case CHECKED:
default:
is = new BufferedInputStream(fis);
try {
switch (getStreamMode(file.getName())) {
case GZIP:
is = new GZIPInputStream(fis);
break;
case SNAPPY:
is = new SnappyInputStream(fis);
break;
case CHECKED:
default:
is = new BufferedInputStream(fis);
}
return new CheckedInputStream(is, new Adler32());
} catch (IOException e) {
fis.close();
throw e;
}
return new CheckedInputStream(is, new Adler32());
}

/**
Expand All @@ -129,9 +134,16 @@ public static CheckedOutputStream getOutputStream(File file, boolean fsync) thro
OutputStream os;
switch (streamMode) {
case GZIP:
os = new GZIPOutputStream(fos);
try {
os = new GZIPOutputStream(fos);
} catch (IOException e) {
fos.close();
throw e;
}
break;
case SNAPPY:
// Unlike SnappyInputStream, the SnappyOutputStream
// constructor cannot throw an IOException.
os = new SnappyOutputStream(fos);
break;
case CHECKED:
Expand Down