You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2021/05/24 16:24:20 UTC

[GitHub] [hadoop] Nargeshdb commented on a change in pull request #3027: HDFS-16031. Possible Resource Leak in org.apache.hadoop.hdfs.server.aliasmap#InMemoryAliasMap

Nargeshdb commented on a change in pull request #3027:
URL: https://github.com/apache/hadoop/pull/3027#discussion_r638098989



##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryAliasMap.java
##########
@@ -320,21 +320,18 @@ static File createSnapshot(InMemoryAliasMap aliasMap) throws IOException {
   private static File getCompressedAliasMap(File aliasMapDir)
       throws IOException {
     File outCompressedFile = new File(aliasMapDir.getParent(), TAR_NAME);
-    BufferedOutputStream bOut = null;
-    GzipCompressorOutputStream gzOut = null;
-    TarArchiveOutputStream tOut = null;
-    try {
-      bOut = new BufferedOutputStream(
-          Files.newOutputStream(outCompressedFile.toPath()));
-      gzOut = new GzipCompressorOutputStream(bOut);
-      tOut = new TarArchiveOutputStream(gzOut);
+
+    try (BufferedOutputStream bOut = new BufferedOutputStream(
+            Files.newOutputStream(outCompressedFile.toPath()));
+         GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(bOut);
+         TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)){
+
       addFileToTarGzRecursively(tOut, aliasMapDir, "", new Configuration());
-    } finally {
       if (tOut != null) {
         tOut.finish();
       }

Review comment:
       If we define `tOut` in try-with-resources block, then we don't have access to `tOut` in finally block. I checked `close()` method in `TarArchiveOutputStream` and `finish()` is called there so I think we don't need to call `finish` on `tOut`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org