From a853b4e1b5742faadf7b667b0cebbc0dac001395 Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Mon, 16 Jan 2017 13:45:22 -0800 Subject: [PATCH] HDFS-11342. Fix FileInputStream leak in loadLastPartialChunkChecksum. Contributed by Chen Liang. --- .../server/datanode/fsdataset/impl/FsVolumeImpl.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java index 042ef6e83e4..f6e6a59aa43 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl; import java.io.BufferedWriter; import java.io.File; +import java.io.FileInputStream; import java.io.FilenameFilter; import java.io.IOException; import java.io.OutputStreamWriter; @@ -1122,9 +1123,11 @@ public class FsVolumeImpl implements FsVolumeSpi { public byte[] loadLastPartialChunkChecksum( File blockFile, File metaFile) throws IOException { // readHeader closes the temporary FileInputStream. - DataChecksum dcs = BlockMetadataHeader - .readHeader(fileIoProvider.getFileInputStream(this, metaFile)) - .getChecksum(); + DataChecksum dcs; + try (FileInputStream fis = fileIoProvider.getFileInputStream( + this, metaFile)) { + dcs = BlockMetadataHeader.readHeader(fis).getChecksum(); + } final int checksumSize = dcs.getChecksumSize(); final long onDiskLen = blockFile.length(); final int bytesPerChecksum = dcs.getBytesPerChecksum();