HDFS-12789. [READ] Image generation tool does not close an opened stream

This commit is contained in:
Virajith Jalaparti 2017-11-08 10:28:50 -08:00 committed by Chris Douglas
parent c293cc8e9b
commit 87dc026bee
1 changed files with 12 additions and 5 deletions

View File

@ -165,16 +165,23 @@ public class ImageWriter implements Closeable {
// create directory and inode sections as side-files. // create directory and inode sections as side-files.
// The details are written to files to avoid keeping them in memory. // The details are written to files to avoid keeping them in memory.
FileOutputStream dirsTmpStream = null;
try {
dirsTmp = File.createTempFile("fsimg_dir", null); dirsTmp = File.createTempFile("fsimg_dir", null);
dirsTmp.deleteOnExit(); dirsTmp.deleteOnExit();
dirs = beginSection(new FileOutputStream(dirsTmp)); dirsTmpStream = new FileOutputStream(dirsTmp);
dirs = beginSection(dirsTmpStream);
} catch (IOException e) {
IOUtils.cleanupWithLogger(null, raw, dirsTmpStream);
throw e;
}
try { try {
inodesTmp = File.createTempFile("fsimg_inode", null); inodesTmp = File.createTempFile("fsimg_inode", null);
inodesTmp.deleteOnExit(); inodesTmp.deleteOnExit();
inodes = new FileOutputStream(inodesTmp); inodes = new FileOutputStream(inodesTmp);
} catch (IOException e) { } catch (IOException e) {
// appropriate to close raw? IOUtils.cleanupWithLogger(null, raw, dirsTmpStream, dirs);
IOUtils.cleanup(null, raw, dirs);
throw e; throw e;
} }