From 87dc026beec5d69a84771631ebca5fadb2f7195b Mon Sep 17 00:00:00 2001 From: Virajith Jalaparti Date: Wed, 8 Nov 2017 10:28:50 -0800 Subject: [PATCH] HDFS-12789. [READ] Image generation tool does not close an opened stream --- .../hdfs/server/namenode/ImageWriter.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/ImageWriter.java b/hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/ImageWriter.java index ea1888afb6..390bb393d8 100644 --- a/hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/ImageWriter.java +++ b/hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/ImageWriter.java @@ -165,16 +165,23 @@ public ImageWriter(Options opts) throws IOException { // create directory and inode sections as side-files. // The details are written to files to avoid keeping them in memory. - dirsTmp = File.createTempFile("fsimg_dir", null); - dirsTmp.deleteOnExit(); - dirs = beginSection(new FileOutputStream(dirsTmp)); + FileOutputStream dirsTmpStream = null; + try { + dirsTmp = File.createTempFile("fsimg_dir", null); + dirsTmp.deleteOnExit(); + dirsTmpStream = new FileOutputStream(dirsTmp); + dirs = beginSection(dirsTmpStream); + } catch (IOException e) { + IOUtils.cleanupWithLogger(null, raw, dirsTmpStream); + throw e; + } + try { inodesTmp = File.createTempFile("fsimg_inode", null); inodesTmp.deleteOnExit(); inodes = new FileOutputStream(inodesTmp); } catch (IOException e) { - // appropriate to close raw? - IOUtils.cleanup(null, raw, dirs); + IOUtils.cleanupWithLogger(null, raw, dirsTmpStream, dirs); throw e; }