Skip to content

Commit 115623a

Browse files
authored
HDFS-15791. Possible Resource Leak in FSImageFormatProtobuf. (apache#2652)
1 parent 84b154e commit 115623a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,20 @@ public InputStream getInputStreamForSection(FileSummary.Section section,
269269
String compressionCodec)
270270
throws IOException {
271271
FileInputStream fin = new FileInputStream(filename);
272-
FileChannel channel = fin.getChannel();
273-
channel.position(section.getOffset());
274-
InputStream in = new BufferedInputStream(new LimitInputStream(fin,
275-
section.getLength()));
272+
try {
276273

277-
in = FSImageUtil.wrapInputStreamForCompression(conf,
278-
compressionCodec, in);
279-
return in;
274+
FileChannel channel = fin.getChannel();
275+
channel.position(section.getOffset());
276+
InputStream in = new BufferedInputStream(new LimitInputStream(fin,
277+
section.getLength()));
278+
279+
in = FSImageUtil.wrapInputStreamForCompression(conf,
280+
compressionCodec, in);
281+
return in;
282+
} catch (IOException e) {
283+
fin.close();
284+
throw e;
285+
}
280286
}
281287

282288
/**

0 commit comments

Comments
 (0)