From 3a355282c932bdbbdcbd9a773779413da188d638 Mon Sep 17 00:00:00 2001 From: Narges Shadab <54193416+Nargeshdb@users.noreply.github.com> Date: Fri, 19 Mar 2021 01:36:48 -0700 Subject: [PATCH] HDFS-15868. Possible Resource Leak in EditLogFileOutputStream (#2736). Contributed by Narges Shadab. Reviewed-by: He Xiaoqiao (cherry picked from commit f5f3fc6fe90e3bb2ee783f956432db11e655b9e3) --- .../hdfs/server/namenode/EditLogFileOutputStream.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java index 4919ea44e0f..7fe84307df1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java @@ -88,7 +88,12 @@ public class EditLogFileOutputStream extends EditLogOutputStream { } else { rp = new RandomAccessFile(name, "rw"); } - fp = new FileOutputStream(rp.getFD()); // open for append + try { + fp = new FileOutputStream(rp.getFD()); // open for append + } catch (IOException e) { + IOUtils.closeStream(rp); + throw e; + } fc = rp.getChannel(); fc.position(fc.size()); }