HDFS-16031. Possible Resource Leak in org.apache.hadoop.hdfs.server.aliasmap#InMemoryAliasMap (#3027)

(cherry picked from commit 3fdeb7435a)
This commit is contained in:
Narges Shadab 2021-05-25 22:43:41 -07:00 committed by Akira Ajisaka
parent 48aa23eb3b
commit 41025cd585
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
1 changed files with 7 additions and 13 deletions

View File

@ -320,21 +320,15 @@ public class InMemoryAliasMap implements InMemoryAliasMapProtocol,
private static File getCompressedAliasMap(File aliasMapDir) private static File getCompressedAliasMap(File aliasMapDir)
throws IOException { throws IOException {
File outCompressedFile = new File(aliasMapDir.getParent(), TAR_NAME); File outCompressedFile = new File(aliasMapDir.getParent(), TAR_NAME);
BufferedOutputStream bOut = null;
GzipCompressorOutputStream gzOut = null; try (BufferedOutputStream bOut = new BufferedOutputStream(
TarArchiveOutputStream tOut = null;
try {
bOut = new BufferedOutputStream(
Files.newOutputStream(outCompressedFile.toPath())); Files.newOutputStream(outCompressedFile.toPath()));
gzOut = new GzipCompressorOutputStream(bOut); GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(bOut);
tOut = new TarArchiveOutputStream(gzOut); TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)){
addFileToTarGzRecursively(tOut, aliasMapDir, "", new Configuration()); addFileToTarGzRecursively(tOut, aliasMapDir, "", new Configuration());
} finally {
if (tOut != null) {
tOut.finish();
}
IOUtils.cleanupWithLogger(null, tOut, gzOut, bOut);
} }
return outCompressedFile; return outCompressedFile;
} }