HDFS-15791. Possible Resource Leak in FSImageFormatProtobuf. (#2652)

(cherry picked from commit 115623a6ee4eb7391c7c26e1728fa153c0698803)
This commit is contained in:
Narges Shadab 2021-02-01 01:56:59 -08:00 committed by Wei-Chiu Chuang
parent 3a355282c9
commit f07bde90c9

View File

@ -271,6 +271,8 @@ public final class FSImageFormatProtobuf {
String compressionCodec)
throws IOException {
FileInputStream fin = new FileInputStream(filename);
try {
FileChannel channel = fin.getChannel();
channel.position(section.getOffset());
InputStream in = new BufferedInputStream(new LimitInputStream(fin,
@ -279,6 +281,10 @@ public final class FSImageFormatProtobuf {
in = FSImageUtil.wrapInputStreamForCompression(conf,
compressionCodec, in);
return in;
} catch (IOException e) {
fin.close();
throw e;
}
}
/**